No module named pkg_resources

2018-12-31 14:14发布

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?

30条回答
柔情千种
2楼-- · 2018-12-31 14:34

If you are using Python 3, you should use pip3 instead of pip. The command looks like $ pip3 install requirements.txt

查看更多
栀子花@的思念
3楼-- · 2018-12-31 14:35

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.

查看更多
倾城一夜雪
4楼-- · 2018-12-31 14:35

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
查看更多
君临天下
5楼-- · 2018-12-31 14:35

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/)

查看更多
泛滥B
6楼-- · 2018-12-31 14:36

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
查看更多
永恒的永恒
7楼-- · 2018-12-31 14:36

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.

查看更多
登录 后发表回答