问题的根源通常是bin
(Linux)或Scripts
(Windows)子目录中的过时脚本。我将以我遇到的问题为例对此进行解释。
我在用户站点包中安装了virtualenv 1.10版本(实际上,它在用户站点包中而不是系统站点包中是无关紧要的)
pdobrogost@host:~$ which virtualenv
/home/users/pdobrogost/.local/bin/virtualenv
pdobrogost@host:~$ virtualenv --version
1.10
将其升级到版本1.11后,出现以下错误:
pdobrogost@host:~$ virtualenv --version
Traceback (most recent call last):
File "/home/users/pdobrogost/.local/bin/virtualenv", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 2701, in <module>
return self.__dep_map
File "build/bdist.linux-x86_64/egg/pkg_resources.py", line 572, in resolve
if insert:
pkg_resources.DistributionNotFound: virtualenv==1.10
/home/users/pdobrogost/.local/bin/virtualenv
错误消息中提到的文件如下所示:
#!/opt/python/2.7.5/bin/python2.7
# EASY-INSTALL-ENTRY-SCRIPT: 'virtualenv==1.10','console_scripts','virtualenv'
__requires__ = 'virtualenv==1.10'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('virtualenv==1.10', 'console_scripts', 'virtualenv')()
)
在那里,我们看到该virtualenv
脚本未更新,仍然需要先前安装的virtualenv 1.10版本。
现在,像这样重新安装virtualenv
pdobrogost@host:~$ pip install --user --upgrade virtualenv
Downloading/unpacking virtualenv from https://pypi.python.org/packages/py27/v/virtualenv/virtualenv-1.11.1-py27-none-any.whl#md5=265770b61de41d34d2e9fdfddcdf034c
Using download cache from /home/users/pdobrogost/.pip_download_cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fpy27%2Fv%2Fvirtualenv%2Fvirtualenv-1.11.1-py27-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...
无济于事(两者都不是pip install --user --upgrade --force-reinstall virtualenv
),因为脚本/home/users/pdobrogost/.local/bin/virtualenv
保持不变。
我可以解决此问题的唯一方法是从/home/users/pdobrogost/.local/bin/
文件夹中手动删除virtualenv *脚本,然后再次安装virtualenv。之后,新生成的脚本将引用该软件包的正确版本:
pdobrogost@host:~$ virtualenv --version
1.11