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

I use CentOS 6.7, and my python was just upgrade from 2.6.6 to 2.7.11, after tried so many different answer, finally the following one does the job:

sudo yum install python-devel

Hope help someone in the same situation.

查看更多
千与千寻千般痛.
3楼-- · 2018-12-31 14:49

ImportError: No module named pkg_resources: the solution is to reinstall python pip using the following Command are under.

Step: 1 Login in root user.

sudo su root

Step: 2 Uninstall python-pip package if existing.

apt-get purge -y python-pip

Step: 3 Download files using wget command(File download in pwd )

wget https://bootstrap.pypa.io/get-pip.py

Step: 4 Run python file.

python ./get-pip.py

Step: 5 Finaly exicute installation command.

apt-get install python-pip

Note: User must be root.

查看更多
姐姐魅力值爆表
4楼-- · 2018-12-31 14:49

I experienced that error in my Google App Engine environment. And pip install -t lib setuptools fixed the issue.

查看更多
冷夜・残月
5楼-- · 2018-12-31 14:50

For me, this error was being caused because I had a subdirectory called "site"! I don't know if this is a pip bug or not, but I started with:

/some/dir/requirements.txt /some/dir/site/

pip install -r requirements.txt wouldn't work, giving me the above error!

renaming the subfolder from "site" to "src" fixed the problem! Maybe pip is looking for "site-packages"? Crazy.

查看更多
梦寄多情
6楼-- · 2018-12-31 14:51

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
查看更多
初与友歌
7楼-- · 2018-12-31 14:53
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

查看更多
登录 后发表回答