773π
July 2018 Update
Most people should now use pip install setuptools
(possibly with sudo
).
Some may need to (re)install the python-setuptools
package via their package manager (apt-get install
, yum install
, etc.).
This issue can be highly dependent on your OS and dev environment. See the legacy/other answers below if the above isnβt working for you.
Explanation
This error message is caused by a missing/broken Python setuptools
package. Per Matt M.βs comment and setuptools issue #581, the bootstrap script referred to below is no longer the recommended installation method.
The bootstrap script instructions will remain below, in case itβs still helpful to anyone.
Legacy Answer
I encountered the same ImportError
today while trying to use pip. Somehow the setuptools
package had been deleted in my Python environment.
To fix the issue, run the setup script for setuptools
:
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
(or if you donβt have wget
installed (e.g. OS X), try
curl https://bootstrap.pypa.io/ez_setup.py | python
possibly with sudo
prepended.)
If you have any version of distribute
, or any setuptools
below 0.6, you will have to uninstall it first.*
See Installation Instructions for further details.
* If you already have a working distribute
, upgrading it to the βcompatibility wrapperβ that switches you over to setuptools
is easier. But if things are already broken, donβt try that.
150π
sudo apt-get install --reinstall python-pkg-resources
fixed it for me in Debian. Seems like uninstalling some .deb packages (twisted set in my case) has broken the path python uses to find packages
- [Django]-How to upload a file in Django?
- [Django]-Django Multiple Authentication Backend for one project
- [Django]-Django 1.7 β App 'your_app_name' does not have migrations
76π
I have seen this error while trying to install rhodecode to a virtualenv on ubuntu 13.10. For me the solution was to run
pip install --upgrade setuptools
pip install --upgrade distribute
before I run easy_install rhodecode.
- [Django]-Where does pip install its packages?
- [Django]-Serializer call is showing an TypeError: Object of type 'ListSerializer' is not JSON serializable?
- [Django]-Django: How can I create a multiple select form?
37π
It also happened to me. I think the problem will happen if the requirements.txt contains a βdistributeβ entry while the virtualenv uses setuptools. Pip will try to patch setuptools to make room for distribute, but unfortunately it will fail half way.
The easy solution is delete your current virtualenv then make a new virtualenv with βdistribute argument.
An example if using virtualenvwrapper:
$ deactivate
$ rmvirtualenv yourenv
$ mkvirtualenv yourenv --distribute
$ workon yourenv
$ pip install -r requirements.txt
- [Django]-How to server HTTP/2 Protocol with django
- [Django]-Printing Objects in Django
- [Django]-Django Framework β Is there a shutdown event that can be subscribed to?
18π
In CentOS 6 installing the package python-setuptools fixed it.
yum install python-setuptools
- [Django]-Authenticate by IP address in Django
- [Django]-Django, Models & Forms: replace "This field is required" message
- [Django]-Django FileField upload is not working for me
18π
After trying several of these answers, then reaching out to a colleague, what worked for me on Ubuntu 16.04 was:
pip install --force-reinstall -U setuptools
pip install --force-reinstall -U pip
In my case, it was only an old version of pillow 3.1.1 that was having trouble (pillow 4.x worked fine), and thatβs now resolved!
- [Django]-Django rest framework: query parameters in detail_route
- [Django]-Disable session creation in Django
- [Django]-Django CMS fails to synch db or migrate
14π
I had this error earlier and the highest rated answer gave me an error trying to download the ez_setup.py
file. I found another source so you can run the command:
curl http://peak.telecommunity.com/dist/ez_setup.py | python
I found that I also had to use sudo
to get it working, so you may need to run:
sudo curl http://peak.telecommunity.com/dist/ez_setup.py | sudo python
Iβve also created another location that the script can be downloaded from:
- [Django]-Django custom management commands: AttributeError: 'module' object has no attribute 'Command'
- [Django]-Why won't Django use IPython?
- [Django]-The QuerySet value for an exact lookup must be limited to one result using slicing. Filter error
9π
A lot of answers are recommending the following but if you read through the source of that script, youβll realise itβs deprecated.
wget https://bootstrap.pypa.io/ez_setup.py -O - | python
If your pip is also broken, this wonβt work either.
pip install setuptools
I found I had to run the command from Ensure pip, setuptools, and wheel are up to date, to get pip working again.
python -m pip install --upgrade pip setuptools wheel
- [Django]-How to get superuser details in Django?
- [Django]-Multiple annotate Sum terms yields inflated answer
- [Django]-Django Rest Framework custom response message
8π
Needed a little bit more sudo. Then used easy_install to install pip. Works.
sudo wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
sudo easy_install pip
- [Django]-How to check if ManyToMany field is not empty?
- [Django]-What's the idiomatic Python equivalent to Django's 'regroup' template tag?
- [Django]-Pytest.mark.parametrize with django.test.SimpleTestCase
6π
I fixed the error with virtualenv by doing this:
Copied pkg_resources.py from
/Library/Python/2.7/site-packages/setuptools
to
/Library/Python/2.7/site-packages/
This may be a cheap workaround, but it worked for me.
.
If setup tools doesnβt exist, you can try installing system-site-packages by typing virtualenv --system-site-packages /DESTINATION DIRECTORY
, changing the last part to be the directory you want to install to. pkg_rousources.py
will be under that directory in lib/python2.7/site-packages
- [Django]-How to assign items inside a Model object with Django?
- [Django]-IOS app with Django
- [Django]-Warning: Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'
5π
You can use the command
sudo apt-get install --reinstall python3-pkg-resources
if you are using python3 , this was the case with me.
- [Django]-Django admin TabularInline β is there a good way of adding a custom html column?
- [Django]-Filtering using viewsets in django rest framework
- [Django]-Pagination in Django-Rest-Framework using API-View
5π
I ran into this problem after installing the latest Python version 3.10.4
.
Somehow, the setuptools
package and pip were deleted.
I used the following command to resolve the issue :
in [Windows]
py -m ensurepip --default-pip
- [Django]-Get count of related model efficiently in Django
- [Django]-How do I run tests against a Django data migration?
- [Django]-Django QuerySet order
4π
the simple resoluition is that you can use conda to upgrade setuptools or entire enviroment. (Specially for windows user.)
conda upgrade -c anaconda setuptools
if the setuptools is removed, you need to install setuptools again.
conda install -c anaconda setuptools
if these all methodes doesnβt work, you can upgrade conda environement. But I do not recommend that you need to reinstall and uninstall some packages because after that it will exacerbate the situation.
- [Django]-Testing nginx without domain name
- [Django]-Saving ModelForm error(User_Message could not be created because the data didn't validate)
- [Django]-Import data from excel spreadsheet to django model
3π
For me, this error was being caused because I had a subdirectory called βsiteβ! I donβt know if this is a pip bug or not, but I started with:
/some/dir/requirements.txt
/some/dir/site/
pip install -r requirements.txt wouldnβt work, giving me the above error!
renaming the subfolder from βsiteβ to βsrcβ fixed the problem! Maybe pip is looking for βsite-packagesβ? Crazy.
- [Django]-Django: Record with max element
- [Django]-Django Rest Framework Conditional Field on Serializer
- [Django]-Django + Ajax
3π
For me, it turned out to be a permissions problem on site-packages
. Since itβs only my dev environment, I raised the permissions and everything is working again:
sudo chmod -R a+rwx /path/to/my/venv/lib/python2.7/site-packages/
- [Django]-Django Generic Views using decorator login_required
- [Django]-How do I deploy Django on AWS?
- [Django]-A field with precision 10, scale 2 must round to an absolute value less than 10^8
2π
I had this problem when I had activated my virtualenv as a different user than the one who created it. It seems to be a permission problem. I discovered this when I tried the answer by @cwc and saw this in the output:
Installing easy_install script to /path/env/bin
error: /path/env/bin/easy_install: Permission denied
Switching back to the user that created the virtualenv, then running the original pip install
command went without problems. Hope this helps!
- [Django]-Ignoring Django Migrations in pyproject.toml file for Black formatter
- [Django]-Check if celery beat is up and running
- [Django]-Naming convention for Django URL, templates, models and views
2π
I had this problem today as well. I only got the problem inside the virtual env.
The solution for me was deactivating the virtual env, deleting and then uninstalling virtualenv with pip and reinstalling it. After that I created a new virtual env for my project, then pip worked fine both inside the virtual environment as in the normal environment.
- [Django]-Embedding JSON objects in script tags
- [Django]-Django: How to format a DateField's date representation?
- [Django]-"<Message: title>" needs to have a value for field "id" before this many-to-many relationship can be used.
2π
Looks like they have moved away from bitbucket and are now on github (https://github.com/pypa/setuptools)
Command to run is:
wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
- [Django]-Allowing RabbitMQ-Server Connections
- [Django]-Storing an Integer Array in a Django Database
- [Django]-Django: Reference to an outer query may only be used in a subquery
2π
If you are encountering this issue with an application installed via conda, the solution (as stated in this bug report) is simply to install setup-tools with:
conda install setuptools
- [Django]-What is related_name used for?
- [Django]-Django.contrib.auth.logout in Django
- [Django]-How do I match the question mark character in a Django URL?
2π
On Windows, with python 3.7, this worked for me:
pip install --upgrade setuptools --user
--user
installs packages in your home directory, which doesnβt require admin privileges.
- [Django]-Saving ModelForm error(User_Message could not be created because the data didn't validate)
- [Django]-Separating form input and model validation in Django?
- [Django]-Python Socket.IO client for sending broadcast messages to TornadIO2 server
1π
Apparently youβre missing setuptools. Some virtualenv versions use distribute instead of setuptools by default. Use the --setuptools
option when creating the virtualenv or set the VIRTUALENV_SETUPTOOLS=1
in your environment.
- [Django]-Django REST framework post array of objects
- [Django]-How do you use the django-filter package with a list of parameters?
- [Django]-How to use regex in django query
1π
None of the posted answers worked for me, so I reinstalled pip and it worked!
sudo apt-get install python-setuptools python-dev build-essential
sudo easy_install pip
pip install --upgrade setuptools
(reference: http://www.saltycrane.com/blog/2010/02/how-install-pip-ubuntu/)
- [Django]-Why is __init__ module in django project loaded twice
- [Django]-Running Django with FastCGI or with mod_python
- [Django]-How to recursively query in django efficiently?
1π
In my case, I had 2 python versions installed initially and later I had deleted the older one. So while creating the virtual environment
virtualenv venv
was referring to the uninstalled python
What worked for me
python3 -m virtualenv venv
Same is true when you are trying to use pip.
- [Django]-Django Background Task
- [Django]-No handlers could be found for logger
- [Django]-What does on_delete do on Django models?
1π
I encountered this error in a poetry environment.
Steps I took to resolve it:
- Add setuptools as a dev dependency with
poetry add --dev setuptools
- Install setuptools in the poetry env using
poetry run pip install setuptools
- [Django]-Django: how to do calculation inside the template html page?
- [Django]-Django template can't see CSS files
- [Django]-Data Mining in a Django/Postgres application
0π
I came across this answer when I was trying to follow this guide for OSX. What worked for me was, after running python get-pip
, I had to ALSO easy_install pip
. That fixed the issue of not being able to run pip at all. I did have a bunch of old macport stuff installed. That may have conflicted.
- [Django]-ModuleNotFoundError: No module named 'grp' on windows
- [Django]-Django: Safely Remove Old Migrations?
- [Django]-Altering one query parameter in a url (Django)
0π
On windows, I installed pip downloaded from www.lfd.uci.edu/~gohlke/pythonlibs/ then encontered this problem.
So I should have installed setuptools(easy_install) first.
- [Django]-Django β Website Home Page
- [Django]-How can I serialize a queryset from an unrelated model as a nested serializer?
- [Django]-Django Generic Views using decorator login_required
0π
just reinstall your setuptools
by :
$ sudo wget https://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefefe74e
$ tar -zxvf setuptools-0.6c11.tar.gz
$ cd setuptools-0.6c11/
$ sudo python setup.py build
$ sudo python setup.py install
$ sudo pip install --upgrade setuptools
then everything will be fine.
- [Django]-Allowing only super user login
- [Django]-Detect mobile, tablet or Desktop on Django
- [Django]-Django create userprofile if does not exist
0π
I use CentOS 6.7, and my python was just upgrade from 2.6.6 to 2.7.11, after tried so many different answer, finally the following one does the job:
sudo yum install python-devel
Hope help someone in the same situation.
- [Django]-Default value for user ForeignKey with Django admin
- [Django]-How to server HTTP/2 Protocol with django
- [Django]-Django β accessing the RequestContext from within a custom filter
0π
I ran into this problem after updating my Ubuntu build. It seems to have gone through and removed set up tools in all of my virtual environments.
To remedy this I reinstalled the virtual environment back into the target directory. This cleaned up missing setup tools and got things running again.
e.g.:
~/RepoDir/TestProject$ virtualenv TestEnvironmentDir
- [Django]-Django β getting Error "Reverse for 'detail' with no arguments not found. 1 pattern(s) tried:" when using {% url "music:fav" %}
- [Django]-What is the difference between null=True and blank=True in Django?
- [Django]-How to make two django projects share the same database
0π
For me a good fix was to use --no-download
option to virtualenv (VIRTUALENV_NO_DOWNLOAD=1 tox
for tox.)
- [Django]-Django: Filter a Queryset made of unions not working
- [Django]-Multiple annotate Sum terms yields inflated answer
- [Django]-Create custom buttons in admin change_form in Django
- [Django]-How do I use django rest framework to send a file in response?
- [Django]-What is a "django backend"?
- [Django]-Django-celery: No result backend configured
0π
ImportError: No module named pkg_resources: the solution is to reinstall python pip using the following Command are under.
Step: 1 Login in root user.
sudo su root
Step: 2 Uninstall python-pip package if existing.
apt-get purge -y python-pip
Step: 3 Download files using wget command(File download in pwd
)
wget https://bootstrap.pypa.io/get-pip.py
Step: 4 Run python file.
python ./get-pip.py
Step: 5 Finaly exicute installation command.
apt-get install python-pip
Note: User must be root.
- [Django]-Django models: Only permit one entry in a model?
- [Django]-Exclude fields in Django admin for users other than superuser
- [Django]-Django: Use of DATE_FORMAT, DATETIME_FORMAT, TIME_FORMAT in settings.py?
0π
I experienced that error in my Google App Engine environment. And pip install -t lib setuptools
fixed the issue.
- [Django]-Name '_' is not defined
- [Django]-ValueError: The field admin.LogEntry.user was declared with a lazy reference
- [Django]-Altering one query parameter in a url (Django)
0π
I have had the same problem when I used easy-install to install pip for python 2.7.14. For me the solution was (might not be the best, but worked for me, and this is probably the simplest) that the folder that contained the easy-install.py
also contained a folder pkg_resources
, and i have copy-pasted this folder into the same folder where my pip-script.py
script was (python27\Scripts
).
Since then, I found it in the python27\Lib\site-packages\pip-9.0.1-py2.7.egg\pip\_vendor
folder as well, it might be a better solution to modify the pip-script.py
file to import this.
- [Django]-Create a field whose value is a calculation of other fields' values
- [Django]-What is the difference render() and redirect() in Django?
- [Django]-Inline in ModelForm
0π
yum -y install python-setuptools
i configure the Ceph there is a problem execute command "$ ceph-deploy new node1"
,
and I execute the command "$ yum -y install python-setuptools"
,
then the problem is gone.Thanks
- [Django]-POST jQuery array to Django
- [Django]-Are there any plans to officially support Django with IIS?
- [Django]-How can I chain Django's "in" and "iexact" queryset field lookups?
- [Django]-Uninstall Django completely
- [Django]-Is there a list of Pytz Timezones?
- [Django]-How does one make logging color in Django/Google App Engine?
0π
I caused this error (or very similar) by removing the "/Library/Python/2.7/site-packages/" directory from my machine thinking it was a local cache. Only easy_install stopped working (pip was fine).
None of the items listed here helped me but I was able to recover by downloading the latest from https://www.python.org/downloads/ and installing it. Luckily I was not on latest, as I believe otherwise I would have had to reinstall.
I suspect (but not 100% sure) I also needed to open a new terminal (or new tab in terminal) to have it work.
- [Django]-How to monkey patch Django?
- [Django]-Do we need to upload virtual env on github too?
- [Django]-How can I temporarily disable a foreign key constraint in MySQL?
-1π
If you are using Python 3, you should use pip3 instead of pip. The command looks like $ pip3 install requirements.txt
- [Django]-How to merge consecutive database migrations in django 1.9+?
- [Django]-Django: list all reverse relations of a model
- [Django]-Django, Models & Forms: replace "This field is required" message