I'm deploying a Django app to a dev server and am hitting this error when i run pip install 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?
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:I found that I also had to use
sudo
to get it working, so you may need to run:I've also created another location that the script can be downloaded from:
https://gist.github.com/ajtrichards/42e73562a89edb1039f3
After trying several of these answers, then reaching out to a colleague, what worked for me on Ubuntu 16.04 was:
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!
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-packagesFor 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: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 theVIRTUALENV_SETUPTOOLS=1
in your environment.On Opensuse 42.1 the following fixed this issue: