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:37

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
查看更多
心情的温度
3楼-- · 2018-12-31 14:37

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.

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

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

查看更多
人气声优
5楼-- · 2018-12-31 14:39

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.

查看更多
听够珍惜
6楼-- · 2018-12-31 14:40

For me a good fix was to use --no-download option to virtualenv (VIRTUALENV_NO_DOWNLOAD=1 tox for tox.)

查看更多
时光乱了年华
7楼-- · 2018-12-31 14:42

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.

查看更多
登录 后发表回答