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 withsudo).Some may need to (re)install the
python-setuptoolspackage 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
setuptoolspackage. 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
ImportErrortoday while trying to use pip. Somehow thesetuptoolspackage had been deleted in my Python environment.To fix the issue, run the setup script for
setuptools:(or if you don’t have
wgetinstalled (e.g. OS X), trypossibly with
sudoprepended.)If you have any version of
distribute, or anysetuptoolsbelow 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 tosetuptoolsis easier. But if things are already broken, don’t try that.