Solving problem is about exposing yourself to as many situations as possible like No module named pkg_resources and practice these strategies over and over. With time, it becomes second nature and a natural way you approach any problems in general. Big or small, always start with a plan, use other strategies mentioned here till you are confident and ready to code the solution.
In this post, my aim is to share an overview the topic about No module named pkg_resources, which can be followed any time. Take easy to follow this discuss.
I’m deploying a Django app to a dev server and am hitting this error when I run
pip install -r requirements.txt:
Traceback (most recent call last): File "/var/www/mydir/virtualenvs/dev/bin/pip", line 5, in <module> from pkg_resources import load_entry_point ImportError: No module named pkg_resources
pkg_resources appears to be distributed with
setuptools. Initially I thought this might not be installed to the Python in the virtualenv, so I installed
setuptools 2.6 (same version as Python) to the Python site-packages in the virtualenv with the following command:
sh setuptools-0.6c11-py2.6.egg --install-dir /var/www/mydir/virtualenvs/dev/lib/python2.6/site-packages
EDIT: This only happens inside the virtualenv. If I open a console outside the virtualenv then
pkg_resources is present, but I am still getting the same error.
Any ideas as to why
pkg_resources is not on the path?
July 2018 Update
Most people should now use
pip install setuptools (possibly with
Some may need to (re)install the
python-setuptools package via their package manager (
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.
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.
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
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
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.
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
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.
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
In CentOS 6 installing the package python-setuptools fixed it.
yum install python-setuptools
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:
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!
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