我正在将Django应用程序部署到开发服务器上,当我运行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似乎与setuptools一起分发。最初我认为这可能不会安装到virtualenv中的Python中,因此我使用以下命令将setuptools 2.6(与Python相同版本)安装到virtualenv中的Python站点包中:

sh setuptools-0.6c11-py2.6.egg --install-dir /var/www/mydir/virtualenvs/dev/lib/python2.6/site-packages

编辑:这只发生在virtualenv内部。如果我在virtualenv之外打开一个控制台,那么pkg_resources是存在的,但我仍然得到相同的错误。

关于为什么pkg_resources不在路径上有任何想法吗?


当前回答

我在ubuntu 13.10上试图将rhodecode安装到virtualenv时看到过这个错误。对我来说,解决办法就是逃跑

pip install --upgrade setuptools
pip install --upgrade distribute 

在我运行easy_install rhodecode之前。

其他回答

对我来说,这个错误是因为我有一个名为“site”的子目录!我不知道这是不是pip bug,但我开始说:

/一些/目录/要求.txt /一些/目录/站点/

PIP install -r requirements.txt不能工作,给我上面的错误!

将子文件夹从“site”重命名为“src”修复了这个问题!也许皮普正在寻找“站点包”?疯了。

简单的解决方法是使用conda来升级setuptools或整个环境。(windows用户专用)

conda upgrade -c anaconda setuptools

如果setuptools被移除,需要重新安装setuptools。

conda install -c anaconda setuptools

如果这些方法都不起作用,您可以升级conda环境。但我不建议你重新安装和卸载一些包,因为这将加剧情况。

还需要一点sudo。然后使用easy_install安装pip。的工作原理。

sudo wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
sudo easy_install pip

在Windows上,使用python 3.7,这对我来说是有效的:

pip install --upgrade setuptools --user

——user在你的主目录下安装包,不需要管理员权限。

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.