I am on Redhat, and when I run any fabric scripts I see the following error:
Traceback (most recent call last): File "/usr/bin/fab", line 8, in
from fabric.main import main ImportError: No module named fabric.main
The file /usr/bin/fab is configured to use python 2.7 (/usr/local/bin/python):
#!/usr/local/bin/python
# -*- coding: utf-8 -*- import re import sys
from fabric.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
The result is the same even if I just call fab.
Not sure what else I should be configuring. I have not set up a virtualenv for fab. If I must, I will do so.
I installed python 2.7, and then I installed fab as follows:
wget https://bootstrap.pypa.io/get-pip.py
sudo /usr/local/bin/python get-pip.py
sudo /usr/local/bin/pip install fab
I ended up doing the following:
Install Python 2.7 in a virtualenv (~/virtualenvs/py2.7) by following the top-rated answer from Is it possible to install another version of Python to Virtualenv? by DTing
Install pip in ~/virtualenvs/py2.7/bin/:
wget https://bootstrap.pypa.io/get-pip.py
sudo ~/virtualenvs/py2.7/bin/python2.7 get-pip.py
Install fab in ~/virtualenvs/py2.7/bin:
sudo ~/virtualenvs/py2.7/bin/pip install fab
For some reason, I still did not have the fab file under ~/virtualenvs/py2.7/bin, so I just copied the original /usr/bin/fab that was giving me issues to ~/virtualenvs/py2.7/bin/ and edited it to point to the virtualenv python2.7 (~/virtualenvs/py2.7/bin/python2.7)
Running ~/virtualenvs/py2.7/bin/fab worked, and gave me the following (welcome) error:
Fatal error: Couldn't find any fabfiles!
Remember that -f can be used to specify fabfile path, and use -h for
help.
Aborting.
I am content for now -- since fab seems to work. But if anyone has ideas why the actual fab file was not created in the ~/virtualenvs/py2.7/bin/ directory, I am all ears. Thank you!
Related
After a first phase of testing among different Binance API alternative implementations i decided to try the most diffused one: python-binance.
I'm using Python 3.5 on Ubuntu 16.04.
I installed the module with the following command
pip3 install python-binance
Everything was fine so i decided to run my first test script:
import time
import os
from binance.client import Client
api_key = 'my_binance_api'
api_secret = 'my_binance_secret'
client = Client(my_api_key, my_binance_secret )
Unfortunatly i got the following error:
Traceback (most recent call last):
File "prova.py", line 1, in <module>
from binance.client import Client
File "/myhome/.local/lib/python3.5/site-packages/binance/__init__.py", line 9, in <module>
from binance.client import Client, AsyncClient # noqa
File "/myhome/.local/lib/python3.5/site-packages/binance/client.py", line 41
REQUEST_TIMEOUT: float = 10
^
SyntaxError: invalid syntax
Any idea on how to fix this? Thx
As suggested by #OneCricketeer above, i installed a new version of python (3.8) and then, after forcing the reinstall of python-binance via a new version of PIP (unfortunalty mine gets broken) Binance package start working.
I'm gonna list the procedure (including PIP tweaks) just in case someone else out there wanted to avoid useless and unhealty headaches:
pip install python3.x
pip sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1 #update the manager
sudo update-alternatives --config python (chose the latest version)
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo apt-get install python3.8-distutils
python get-pip.py
Use always
python -m pip
to manage the modules
Thanks
I have my python3 path under /usr/bin, any my pip path under /.local/bin of my local repository.
With some pip modules installed, I can run my code successfully through python3 mycode.py.
But I tried to run the shell script:
#!/usr/bin
echo "starting now..."
nohup python3 mycode.py > log.txt 2>&1 &
echo $! > pid
echo "mycode.py started at pid: "
cat pid
and my python code:
mycode.py
#!/usr/bin/env python3
from aiocqhttp import CQHttp, Event, Message, MessageSegment
...
...
...
It gives me:
Traceback (most recent call last):
File "mycode.py", line 2, in <module>
from aiocqhttp import CQHttp, Event, Message, MessageSegment
ModuleNotFoundError: No module named 'aiocqhttp'
I tried to replace the interpreter of the shell script with my local path, but it doesn't help. How should I run my python codes using the shell script?
In your case, the aiocqhttp was installed in your home directory, and when you invoke the script by sudo, python3 will not be able to know to search in your home (because it is root that is running the process). You may solve it using these two approaches:
Method 1:
sudo -H pip3 install -U aiocqhttp
Install this module system-wide so that every user can find it.
Method 2:
sudo PYTHONPATH=/home/a495488027/.local/lib/python3.8/site-packages python3 mycode.py
Temporarily add the python module search path to sudo and run the code. This is when you doesn't want to install the package system-wide.
Back to your problem,
sudo PYTHONPATH=/home/a495488027/.local/lib/python3.8/site-packages bash script.sh
should do the work.
Quick solution: install the same that you have installed with sudo and then it will be accesible for all users
I've installed the latest python (2.7.9) bundled with pip and setuptools for windows 32-bit. I've tried reinstalling pip but the problem persists.
Here's the error after running pip --version in Administrator cmd:
Traceback (most recent call last):
File "D:\Python\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "D:\Python\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "D:\Python\Scripts\pip.exe\__main__.py", line 5, in <module>
ImportError: cannot import name main
The bug is found in pip 10.0.0.
In linux you need to modify file: /usr/bin/pip from:
from pip import main
if __name__ == '__main__':
sys.exit(main())
to this:
from pip import __main__
if __name__ == '__main__':
sys.exit(__main__._main())
Even though the original question seems to be from 2015, this 'bug' seems to affect users installing pip-10.0.0 as well.
The workaround is not to modify pip, however to change the way pip is called. Instead of calling /usr/bin/pip call pip via Python itself. For example, instead of the below:
pip install <package>
If from Python version 2 (or default Python binary is called python) do :
python -m pip install <package>
or if from Python version 3:
python3 -m pip install <package>
On Ubuntu Server 16, I have the same problem with python27. Try this:
Change
from pip import main
if __name__ == '__main__':
sys.exit(main())
To
from pip._internal import main
if __name__ == '__main__':
sys.exit(main())
On Windows 10, I used the following commands to downgrade pip:
python -m pip uninstall pip
python -m pip install pip==9.0.3
This should also work on Linux and Mac too.
I had the same problem, but uninstall and reinstall with apt and pip didn't work for me.
I saw another solution that presents a easy way to recover pip3 path:
sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
i fixed the problem by reinstalling pip using get-pip.py.
Download get-pip from official link: https://pip.pypa.io/en/stable/installing/#upgrading-pip
run it using commande: python get-pip.py.
And pip is fixed and work perfectly.
On MacOS if you've installed python via Homebrew, change the line in /usr/local/opt/python/libexec/bin/pip
from
from pip.internal import main
to
from pip._internal import main
Or use this one liner: sed -i '' "s/from pip import main/from pip._internal import main/" /usr/local/opt/python/libexec/bin/pip
Explanation:
The issue is caused by the changes in pip version 10 moving internal namespace under main._internal and the bin script put in place by homebrew still looking it from the old place (where it used to be in version 9). Issue and some discussion https://github.com/pypa/pip/issues/5240
If you have a hardlink to pip in your PATH (i.e. if you have multiple python versions installed) and then you upgrade pip, you may also encounter this error.
The solution consists in creating the hardlink again. Or even better, stop using hardlinks and use softlinks.
On Windows 10, I had the same problem. PIP 19 was already installed in my system but wasn't showing up. The error was No Module Found.
python -m pip uninstall pip
python -m pip install pip==9.0.3
Downgrading pip to 9.0.3 worked fine for me.
For those having similar trouble using pip 10 with PyCharm, download the latest version here
try this
#!/usr/bin/python
# GENERATED BY DEBIAN
import sys
# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.i
try:
from pip import main
except ImportError:
from pip._internal import main
if __name__ == '__main__':
sys.exit(main())
A simple solution that works with Ubuntu, but may fix the problem on windows too:
Just call
pip install --upgrade pip
This solved my problem in ubuntu 18.04 when trying to use python3.6:
rm -rf ~/.local/lib/python3.6
You can move the folder to another place using mv instead of deleting it too, for testing:
mv ~/.local/lib/python3.6 ./python3.6_old
Open your terminal linux.
hash -d pip
In our case, in 2020 using Python3, the solution to this problem was to move the Python installation to the cloud-init startup script which instantiated the VM.
We had been encountering this same error when we had been trying to install Python using scripts that were called by users later in the VM's life cycle, but moving the same Python installation code to the cloud-init script eliminated this problem.
It works on ubuntu 16.04.
Step 1:
sudo gedit /home/user_name/.local/bin/pip
a file opens with the content:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
Change the main to __main__ as it appears below:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pip import __main__
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(__main__._main())
Save the file and close it. And you are done!
Attempt to install psutils resulted a big headache...
$ python -V
Python 2.4.2
$ cat /etc/SuSE-release
SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10
PATCHLEVEL = 4
$ cd psutil-2.1.1/
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 17, in ?
from distutils.core import setup, Extension
ImportError: No module named distutils.core
Next - I try to install setuptools to use easy_install:
$ which easy_install
which: no easy_install
$ cd ../setuptools-1.4/
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 12, in ?
from distutils.util import convert_path
ImportError: No module named distutils.util
Trying install distutils from ez_setup.py:
$ python ez_setup.py
Traceback (most recent call last):
File "ez_setup.py", line 278, in ?
main(sys.argv[1:])
File "ez_setup.py", line 210, in main
egg = download_setuptools(version, delay=0)
File "ez_setup.py", line 139, in download_setuptools
from distutils import log
ImportError: No module named distutils
So - how can I install it?
P.S. No, I haven't root on this machine and can't use package manager.
you need to run this (if Error happens on python3) ==> sudo apt-get install python3-distutils --reinstall
you need to run this (if Error happens on python2) ==> sudo apt-get install python2-distutils --reinstall
I have an answer here but I will copy it here
AskUbuntu answer:
Debian has decided that distutils is not a core python package, so it is not included in the last versions of debian and debian-based OSes. You should be able to do sudo apt install python3-distutils and it should work.
However, it did not work for me. I use Parrot OS, which is, as Ubuntu, Debian based. I upgraded my system and pip stopped working for python3.7, and I also got the error ModuleNotFoundError: No module named 'distutils.util'
I tried a lot of stuff to fix it and to reinstall distutils, and I found out by pure luck, that pip3, for python3.8 did work. I then tried python3.7 -m pip3 -V, got /usr/bin/python3.7: No module named pip3 so I decided to have a look in the /usr/lib files.
I looked at /usr/lib/python3/dist-packages and everything looked fine. Then I looked at /usr/lib/python3.7 and saw the folder distutil.
I opened it, and saw the __pycache__, the __init__.py file and a version.py file. I had no idea how many files should be in there, or what the code should be, but I knew that those two files were either wrong or missing another file.
Then I had a look at what was inside /usr/lib/python3.8/distutil and it was totally different. I found the following files:
command Folder
__pycache__ Folder
archive_util.py Python script
bcppcompiler.py Python script
cmd.py Python script
config.py Python script
core.py Python script
cygwinccompiler.py Python script
debug.py Python script
dep_util.py Python script
errors.py Python script
extension.py Python script
fancy_getopt.py Python script
filelist.py Python script
file_util.py Python script
__init__.py Python script
log.py Python script
msvc9compiler.py Python script
_msvccompiler.py Python script
msvccompiler.py Python script
README Plain text file
spawn.py Python script
sysconfig.py Python script
text_file.py Python script
unixccompiler.py Python script
util.py Python script
version.py Python script
versionpredicate.py Python script
This was a lot more promising, and since pip3 did work, I assumed that this distutils worked too, and I tried to copy it to the python3.7 folder by running this command:
sudo cp -r /usr/lib/python3.8/distutil /usr/lib/python3.7/distutil
Then I tried again python3.7 -m pip -V and got
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.7)
Then I tried installing some modules and everything works fine.
I hope this is helpful.
#ciro
I need to do even more to get virtualenv running again (upgraded from 18.04 to 20.04):
sudo cp /usr/lib/python3.8/_sysconfigdata__* /usr/lib/python3.6/
cd /usr/lib/python3.6
sudo ln -s _sysconfigdata_m_linux_x86_64-linux-gnu.py _sysconfigdata_m_x86_64-linux-gnu.py
I am trying to run Tweepy client for Twitter on my Unix account. whenever i try to run setup for Tweepy using the command:
python setup.py
I get this error:
Traceback (most recent call last):
File "setup.py", line 3, in ?
from setuptools import setup, find_packages
ImportError: No module named setuptools
Now i searched on some forums and found i need to add setup tools file. The file i found
setuptools-0.6c11-py2.7.egg
I FTP - ed this file to my unix directory where i have Tweepy client directory and my program which is using Tweepy.
Now, whenever i try to install setup tools using the command
python setuptools-0.6c11-py2.7.egg
I get the error :
python setuptools-0.6c11-py2.7.egg
File "setuptools-0.6c11-py2.7.egg", line 2
if [ `basename $0` = "setuptools-0.6c11-py2.7.egg" ]
^
SyntaxError: invalid syntax
Any clues/suggestions what i must be doing wrong here ?
Don't use setuptools, use distribute. Setuptools is old and deprecated. Until python 3.4 with packaging/distutils2 is around use distribute, which is a fork of old setuptools/distutils.
Simply download the distribute source tarball, unpack and run python setup.py install. Alternatively, you can download distribute-setup.py and just run it.
To install tweepy, run inside a virtualenv:
(venv) $ pip install tweepy
To create a virtual environment and install setuptools/distribute/easy_install, pip, and virtualenv, run:
$ curl -O https://raw.github.com/pypa/virtualenv/master/virtualenv.py
$ python virtualenv.py venv
$ source ./venv/bin/activate
taken from here
The setuptools documentation suggest using sh setuptools-0.6c11-py2.7.egg instead of python setuptools-0.6c11-py2.7.egg.
You get a SyntaxError from python because setuptools-0.6c11-py2.7.egg begins as a shell script:
#!/bin/sh
if [ `basename $0` = "setuptools-0.6c11-py2.7.egg" ]
then exec python2.7 -c "import sys, os; sys.path.insert(0, os.path.abspath('$0')); from setuptools.command.easy_install import bootstrap; sys.exit(bootstrap())" "$#"
else
echo $0 is not the correct name for this egg file.
echo Please rename it back to setuptools-0.6c11-py2.7.egg and try again.
exec false
fi
PK\00\00\00\00F\A3\E...