Can't able to install any python packages [duplicate] - python

I have installed pip for python 3.6 on Ubuntu 14. After I run
sudo apt-get install python3-pip
to install pip3, it works very well. However, after installation, when I am trying to run
pip3 install packagename
to install a new package, something strange occurs:
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 1479, in <module>
register_loader-type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module "importlib._bootstrap" has no attribute "SourceFileLoader"
It seems that I did nothing wrong, and I really cannot figure out the reason.

If you're getting this error running pip install dotenv, this is because the package is called python-dotenv not dotenv.
This worked for me:
sudo pip install python-dotenv

Faced the same problem. I think this is because python3.6 and pip3 were installed from different sources.
I suggest using python's inbuilt facility to install pip i.e
python3 -m ensurepip --upgrade
This should install pip3 and pip3.x where x in python3.x.
Same works for python2 also.

Tried to install Tensorflow in venv on Windows 10 machine with python 3.8 and got the same issue.
What helped for me was:
pip install setuptools --upgrade

I had the same problem on my ubuntu 18.04 with python 3.6. None of the above methods helped, but this one solved the problem:
pip3 uninstall setuptools

I had the same error whatever I asked to pip. I gave a look to this page: https://packaging.python.org/tutorials/installing-packages/
That line is the one that solved my problem:
python3 -m pip install --upgrade pip setuptools wheel

pip install setuptools --upgrade
This command solved my issue. It fixed my problem.

When updating from python3.4 to python3.6 on ubuntu 14.04. The following solved me:
wget https://bootstrap.pypa.io/ez_setup.py -O - | python3

If you face this issue in anaconda environment, simply upgrade setuptools using the following:
conda install -c conda-forge setuptools

That's because you are using an old version of setuptools, check up this issue.

I met the same problem, this is the key:
curl -sS https://bootstrap.pypa.io/get-pip.py | sudo python3

I had faced the same issue on Ubuntu 19.10 and now I upgraded to Ubuntu 20.04 and faced the issue again. This issue is due to broken pip3. So whenever you enter pip3 and hit enter it will show the same error. So instead of using "pip3 uninstall setuptools" use the below code
python3 -m pip uninstall setuptools
It resolved my issue 3rd time

I am facing the same problem, which is solved by downloading the source files of the setuptools and installing the module manually.
The setuptools can be downloaded here:
https://pypi.org/project/setuptools/
After downloading, unzip the package first, then cd to the directory and run
python setup.py install --user

For me the error happened while trying to create a virtual env with python 3.8:
sudo virtualenv venv -ppython3.8
And after trying all the answers here, finally the problem solved by installing the new version of virtualenv (20.0.7):
sudo pip3 install virtualenv

I encountered this error message triggered by a slightly different situation which I'll mention here for anyone who finds this.
This same error also occurs when installing the distribute Python package (which is currently just a compatibility layer in front of setuptools) in Python 3.6 or newer.
In my specific situation I discovered this as I was using pyzmail which has been somewhat abandoned and depends on distribute.
Collecting distribute
Downloading distribute-0.7.3.zip (145 kB)
ERROR: Command errored out with exit status 1:
command: /var/lang/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ssqyqflj/distribute/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ssqyqflj/distribute/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-hgbjn0js
cwd: /tmp/pip-install-ssqyqflj/distribute/
Complete output (15 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/extension.py", line 5, in <module>
from setuptools.dist import _get_unpatched
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/dist.py", line 7, in <module>
from setuptools.command.install import install
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/command/__init__.py", line 8, in <module>
from setuptools.command import install_scripts
File "/tmp/pip-install-ssqyqflj/distribute/setuptools/command/install_scripts.py", line 3, in <module>
from pkg_resources import Distribution, PathMetadata, ensure_directory
File "/tmp/pip-install-ssqyqflj/distribute/pkg_resources.py", line 1518, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

I had the same issue when I tried to install the Slate package in Windows 10, Python 3.7.4 version:
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
The instruction that generated the error:
C:\WINDOWS\system32>python -m pip install slate
The instruction that worked:
C:\WINDOWS\system32>python -m pip install https://github.com/timClicks/slate/archive/master.zip

I had the same problem with my cloud computer. If all above didn't work for you don't worry. Here's how I resolved it:
Download the pip file (pip-version.tar.gz) from:
https://pypi.org/project/pip/#files
For cloud, use this
curl https://files.pythonhosted.org/packages/8e/76/66066b7bc71817238924c7e4b448abdb17eb0c92d645769c223f9ace478f/pip-20.0.2.tar.gz --output pip.tar.gz
Extract the content of the file and cd into the directory.
Run the following in the directory
python3 setup.py install --user
You should have pip3 working without errors.

pip3 install setuptools --upgrade
This also cured the issue on Python 3.9 running on Windows 10 and even on a custom Docker image.

I was having the same issue while using docker-compose. This exact error can be caused by not being the root user. Running the same commands with sudo fixed it for me. I don't not have setup-tools installed, and I'm running pip3. My issue was that IntelliJ didn't have sudo rights, so i had to do it from the terminal.

Above solutions were not working in my case for Ubuntu 20
If you run the following command:
sudo apt install python3-setuptools
Then you might get the result:
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-setuptools is already the newest version (45.2.0-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
But to actually solve it and re-install setuptools try following commands:
sudo apt download python3-setuptools
sudo dpkg -i python3-setuptools_45.2.0-1_all.deb
Note: Change the version of the python package that is downloaded

Traceback (most recent call last):
File "/usr/bin/pipenv", line 6, in <module>
from pkg_resources import load_entry_point
File "/home/myuser/.local/lib/python3.7/site-packages/pkg_resources.py", line
1479, in <module>
Mine looked pretty similar, but for some reason I had a python installation in my home directory .local folder.
I did some of the other answers in this thread to ensure I had good local copy of python, then did:
rm -rf ~/.local

Just go inside the /usr/lib/python3/dist-packages/, first copy setuptools file somewhere and then delete the setuptools. Everything will be okay for deleting you can use:
sudo rm -r setuptools
for copying
sudo cp -r setuptools /...Desktop/
After that if it gives errors just:
sudo pip3 install setuptools==3.8.1
to download again.

Related

Python : setuptools module is already installed but still shows import error

I am trying to install something using "python setup.py install" but it shows me this error :-
Traceback (most recent call last):
File "setup.py", line 3, in <module>
from setuptools import setup
ImportError: No module named setuptools
I have installed this missing module using "pip install setuptools". But still it shows me the same error .I have also tried to install this using "sudo apt-get install python-setuptools" but the problem still remains the same. Help me in this issue
If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setuptools, but will need to upgrade to the latest version:
On Linux or macOS:
pip install -U pip setuptools
On Windows:
python -m pip install -U pip setuptools
If you’re using a Python install on Linux that’s managed by the system package manager (e.g “yum”, “apt-get” etc…), and you want to use the system package manager to install or upgrade pip, then see link

ImportError: No module named extern

I'm getting this error when trying to install any package with pip. I have two pip instances, one with Python 2.7 and other with Python 3.
Could not import setuptools which is required to install from a source distribution.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pip/req/req_install.py", line 375, in setup_py
import setuptools # noqa
File "/usr/local/lib/python2.7/dist-packages/setuptools/__init__.py", line 11, in <module>
from setuptools.extern.six.moves import filterfalse, map
File "/usr/local/lib/python2.7/dist-packages/setuptools/extern/__init__.py", line 1, in <module>
from pkg_resources.extern import VendorImporter
ImportError: No module named extern
Even when I try to install the 'extern' module I get this error. Also when installing with Python itself, like python setup.py install.
Thanks in advance.
sudo apt-get purge python-pkg-resources
sudo apt-get -f install
here actually packages are removed and
purged (any configuration files are deleted too).
-f : Attempt to correct a system with broken dependencies in place.
sudo pip install packagename
#sourcehere
Do this it will work
sudo pip install -U setuptools
I know this is an old thread, but I just wanted to contribute since I ran into this issue and this thread kept coming up in the results.
Note: This was on MacOS 10.12. My shell is zsh and I already have brew installed
First I ran each of these commands
brew install python
brew install python3
This will either install it or you'll receive an "already installed" message as I did.
Next, run the following command
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
And last:
sudo python get-pip.py
Final note: for my install to work, I ended up having to run the command with pip3
sudo pip3 install nameofinstallhere
Not sure whether it is installation issue or packege but it seems like you will not be able to import any package of them, if you have installed python perfectly then
try this commands
step 1 :
$which pip
/usr/local/bin/pip
step 2 :
/usr/local/bin/pip install django
or any of your package name.
I am considering ubuntu(OS)
You can try the following command; it has worked for me:
sudo apt-get install --reinstall python-setuptools

Debian-box and pip3 install <module> [duplicate]

I am trying to pip install the MySQL-python package, but I get an ImportError.
Jans-MacBook-Pro:~ jan$ /Library/Frameworks/Python.framework/Versions/3.3/bin/pip-3.3 install MySQL-python
Downloading/unpacking MySQL-python
Running setup.py egg_info for package MySQL-python
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in <module>
from setup_posix import get_config
File "./setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in <module>
from setup_posix import get_config
File "./setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python
Storing complete log in /Users/jan/.pip/pip.log
Jans-MacBook-Pro:~ jan$
Any ideas?
You can instead use the mysqlclient package as a drop-in replacement for MySQL-python. It is a fork of MySQL-python with added support for Python 3.
I had luck with simply
pip install mysqlclient
in my python3.4 virtualenv after
sudo apt-get install python3-dev libmysqlclient-dev
which is obviously specific to ubuntu/debian, but I just wanted to share my success :)
In Python 3, ConfigParser has been renamed to configparser for PEP 8 compliance. It looks like the package you are installing does not support Python 3.
Here is a code that should work in both Python 2.x and 3.x
Obviously you will need the six module, but it's almost impossible to write modules that work in both versions without six.
try:
import configparser
except:
from six.moves import configparser
pip install configparser
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py
Then try to install the MYSQL-python again.
That Worked for me
MySQL-python is not supported on python3 instead of this you can use mysqlclient
If you are on fedora/centos/Red Hat install following package
yum install python3-devel
pip install mysqlclient
Additional info:
Python 2x
import ConfigParser
Python 3x
import configparser
Compatibility of Python 2/3 for configparser can be solved simply by six library
from six.moves import configparser
If you are using CentOS, then you need to use
yum install python34-devel.x86_64
yum groupinstall -y 'development tools'
pip3 install mysql-connector
pip install mysqlclient
I was having the same problem. Turns out, I needed to install python3 devel on my centos. First, you need to search for the package that is compatible with your system.
yum search python3 | grep devel
Then, install the package as:
yum install -y python3-devel.x86_64
Then, install mysqlclient from pip
pip install mysqlclient
Do pip3 install PyMySQL and then pip3 install mysqlclient.
Worked for me
I got further with Valeres answer:
pip install configparser
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py
Then try to install the MYSQL-python again. That Worked for me
I would suggest to link the file instead of copy it. It is save to update. I linked the file to /usr/lib/python3/ directory.
For me the following command worked:
sudo python3 -m pip install mysql-connector
Try this solution which worked fine for me.
Basically it's to reinstall/upgrade to latest version of mysql from brew, and then installing mysqlclient or MySQL-Python from global pip3 instead of virtualenv pip3.
Then accessing the virtualenv and successfully install mysqlclient or MySQL-Python.
I still have this issue, so I go to /usr/lib/python3.8 and type as sudoer:
cp configparser.py ConfigParser.py
You may have another python version than 3.8.
Following #MaciejNg I tried making a copy, which didn't work:
sudo cp ./env/lib/python3.8/site-packages/configparser.py ./env/lib/python3.8/site-packages/ConfigParser.py
Because configparser.py and ConfigParser.py are identical, I renamed the file:
sudo mv ./env/lib/python3.8/site-packages/configparser.py ./env/lib/python3.8/site-packages/ConfigParser.py
how about checking the version of Python you are using first.
import six
if six.PY2:
import ConfigParser as configparser
else:
import configparser
I run kali linux- Rolling and I came across this problem ,when I tried running cupp.py in the terminal, after updating to python 3.6.0. After some research and trial I found that changing ConfigParser to configparser worked for me but then I came across another issue.
config = configparser.configparser()
AttributeError: module 'configparser' has no attribute 'configparser'
After a bit more research I realised that for python 3 ConfigParser is changed to configparser but note that it has an attribute ConfigParser().
I was getting the same error on Mac OS 10, Python 3.7.6 & Django 2.2.7. I want to use this opportunity to share what worked for me after trying out numerous solutions.
Steps
Installed Connector/Python 8.0.20 for Mac OS from link
Copy current dependencies into requirements.txt file, deactivated the current virtual env, and deleted it using;
create the file if not already created with; touch requirements.txt
copy dependency to file; python -m pip3 freeze > requirements.txt
deactivate and delete current virtual env; deactivate && rm -rf <virtual-env-name>
Created another virtual env and activated it using; python -m venv <virtual-env-name> && source <virtual-env-name>/bin/activate
Install previous dependencies using; python -m pip3 install -r requirements.txt
base on your OS is centos use python3
if you don't known where is configparser.py or ConfigParser.py
pip3 install configparser
find / -name "configparser.py"
cd /usr/local/lib/python3.6/site-packages(base on your environment )
cp configparser.py ConfigParser.py
solved the issue
Kindly to see what is /usr/bin/python pointing to
if it is pointing to python3 or higher change to python2.7
This should solve the issue.
I was getting install error for all the python packages. Abe Karplus's solution & discussion gave me the hint as to what could be the problem.
Then I recalled that I had manually changed the /usr/bin/python from python2.7 to /usr/bin/python3.5, which actually was causing the issue. Once I reverted the same. It got solved.
This worked for me
cp /usr/local/lib/python3.5/configparser.py /usr/local/lib/python3.5/ConfigParser.py

Pip install error. Setuptools.command not found

I'm using a clean instance of Ubuntu server and would like to install some python packages in my virtualenv.
I receive the following output from the command 'pip install -r requirements.txt'
Downloading/unpacking pymongo==2.5.2 (from -r requirements.txt (line 7))
Downloading pymongo-2.5.2.tar.gz (303kB): 303kB downloaded
Running setup.py egg_info for package pymongo
Traceback (most recent call last):
File "<string>", line 3, in <module>
ImportError: No module named setuptools.command
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 3, in <module>
ImportError: No module named setuptools.command
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/redacted/env/build/pymongo
Storing complete log in /home/redacted/.pip/pip.log
Any Idea what's going on?
python version 2.7.3
pip version pip 1.4 from /home/redacted/env/lib/python2.7/site-packages (python 2.7)
Try installing:
sudo apt-get install python-setuptools
if this doesn't work try:
curl -O https://bootstrap.pypa.io/get-pip.py
python get-pip.py
Edit: If you have several (possible conflicting) python installations or environments, the following commands can be useful to debug which executables are being used:
which python
which pip
which easy_install
They should "match". It can happen for example that you have pip installing packages for an EPD or global distribution while the current python that is being used corresponds to a local environment (or something different), in which case it might not be able to see the installed packages.
had the same problem, solved it with
pip install -U setuptools
Elaborating #elyase's Answer.
First check for which python version you want to install setuptools.
Normally both python versions comes default with debian or any linux distro.
So, as per your requirement install setup tools using apt package manager
For python 2.x
sudo apt-get install python-setuptools
For python 3.x
sudo apt-get install python3-setuptools
These instructions solved the problem for me:
first enter these commands
pip install --upgrade pip
pip install --upgrade wheel
pip install setuptools
and then try to install the package that requires setuptools.

pip broke. how to fix DistributionNotFound error?

Whenever i try to use pip I get an error. For exampple:
$ sudo pip install gevent-websocket
Traceback (most recent call last):
File "/usr/local/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2675, in <module>
parse_requirements(__requires__), Environment()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 552, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pip==0.8.1
I feel tempted to change the value of into pip==0.8.2.. but I dont feel dealing with the consequences of 'hacking' up my installation...
I'm running python 2.7 and pip is at version 0.8.2.
I find this problem in my MacBook, the reason is because as #Stephan said, I use easy_install to install pip, and the mixture of both py package manage tools led to the pkg_resources.DistributionNotFound problem.
The resolve is:
easy_install --upgrade pip
Remember: just use one of the above tools to manage your Py packages.
I replaced 0.8.1 in 0.8.2 in /usr/local/bin/pip and everything worked again.
__requires__ = 'pip==0.8.2'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('pip==0.8.2', 'console_scripts', 'pip')()
)
I installed pip through easy_install which probably caused me this headache.
I think this is how you should do it nowadays..
$ sudo apt-get install python-pip python-dev build-essential
$ sudo pip install --upgrade pip
$ sudo pip install --upgrade virtualenv
I had this issue when I was using homebrew. Here is the solution from Issue #26900
python -m pip install --upgrade --force pip
Try re-installing with the get-pip script:
wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py
This is sourced from the pip Github page, and worked for me.
If you're on CentOS make sure you have the YUM package "python-setuptools" installed
yum install python-setuptools
Fixed it for me.
The root of the problem are often outdated scripts in the bin (Linux) or Scripts (Windows) subdirectory. I'll explain this using problem I encountered myself as an example.
I had virtualenv version 1.10 installed in my user site-packages (the fact it's in user site-packages not sytem site-packages is irrelevant here)
pdobrogost#host:~$ which virtualenv
/home/users/pdobrogost/.local/bin/virtualenv
pdobrogost#host:~$ virtualenv --version
1.10
After I upgraded it to version 1.11 I got the following error:
pdobrogost#host:~$ virtualenv --version
Traceback (most recent call last):
File "/home/users/pdobrogost/.local/bin/virtualenv", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2701, in <module>
return self.__dep_map
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 572, in resolve
if insert:
pkg_resources.DistributionNotFound: virtualenv==1.10
File /home/users/pdobrogost/.local/bin/virtualenv mentioned in the error message looked like this:
#!/opt/python/2.7.5/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'virtualenv==1.10','console_scripts','virtualenv'
__requires__ = 'virtualenv==1.10'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('virtualenv==1.10', 'console_scripts', 'virtualenv')()
)
There, we see that virtualenv script was not updated and still requires previously installed version 1.10 of virtualenv.
Now, reinstalling virtualenv like this
pdobrogost#host:~$ pip install --user --upgrade virtualenv
Downloading/unpacking virtualenv from https://pypi.python.org/packages/py27/v/virtualenv/virtualenv-1.11.1-py27-none-any.whl#md5=265770b61de41d34d2e9fdfddcdf034c
Using download cache from /home/users/pdobrogost/.pip_download_cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fpy27%2Fv%2Fvirtualenv%2Fvirtualenv-1.11.1-py27-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...
does not help (neither pip install --user --upgrade --force-reinstall virtualenv) because script /home/users/pdobrogost/.local/bin/virtualenv is left unchanged.
The only way I could fix this was by manually removing virtualenv* scripts from /home/users/pdobrogost/.local/bin/ folder and installing virtualenv again. After this, newly generated scripts refer to the proper version of the package:
pdobrogost#host:~$ virtualenv --version
1.11
I was able to resolve this like so:
$ brew update
$ brew doctor
$ brew uninstall python
$ brew install python --build-from-source # took ~5 mins
$ python --version # => Python 2.7.9
$ pip install --upgrade pip
I'm running w/ the following stuff (as of Jan 2, 2015):
OS X Yosemite
Version 10.10.1
$ brew -v
Homebrew 0.9.5
$ python --version
Python 2.7.9
$ ipython --version
2.2.0
$ pip --version
pip 6.0.3 from /usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.3-py2.7.egg (python 2.7)
$ which pip
/usr/local/bin/pip
I was facing the similar problem in OSx. My stacktrace was saying
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: setuptools>=11.3
Then I did the following
sudo pip install --upgrade setuptools
This solved the problem for me. Hope someone will find this useful.
On Mac OS X (MBP), the following (taken from another answer found herein) resolved my issues:
C02L257NDV33:~ jjohnson$ brew install pip
Error: No available formula for pip
Homebrew provides pip via: `brew install python`. However you will then
have two Pythons installed on your Mac, so alternatively you can:
sudo easy_install pip
C02L257NDV33:~ jjohnson$ sudo easy_install pip
Clearly the root cause here is having a secondary method by which to install python (in my case Homebrew). Hopefully, the people responsible for the pip script can remedy this issue since its still relevant 2 years after first being reported on Stack Overflow.
I had this problem because I installed python/pip with a weird ~/.pydistutils.cfg that I didn't remember writing. Deleted it, reinstalled (with pybrew), and everything was fine.
In my case (sam problem, but other packages) there was no version dependency. A sequence of pip uninstall and pip insstall did help.

Categories

Resources