gpt4 book ai didi

python - 为什么 `virtualenv` 找不到 `pkg_resources` ?

转载 作者:太空狗 更新时间:2023-10-29 20:16:05 26 4
gpt4 key购买 nike

我正在尝试在 Ubuntu 中使用 virtualenv 来安装本地虚拟 Python 环境。当我运行 shell 命令时:

$ virtualenv ./virt_python

它抛出无法导入 pkg_resources 的异常。但是,当我打开 Python shell 并 from pkg_resources import load_entry_point 时,它运行良好。作为引用,完整的堆栈跟踪如下。

$ virtualenv ./virt_python
New python executable in ./virt_python/bin/python
Installing setuptools............done.
Installing pip.......
Complete output from command /home/rpsharp/local/...hon/bin/easy_install /usr/local/lib/pytho...pport/pip-1.1.tar.gz:
Traceback (most recent call last):
File "/home/rpsharp/local/workspace/invest-natcap.invest-3/virt_python/bin/easy_install", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
----------------------------------------
...Installing pip...done.
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.7.1.2', 'console_scripts', 'virtualenv')()
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 928, in main
never_download=options.never_download)
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1042, in create_environment
install_pip(py_executable, search_dirs=search_dirs, never_download=never_download)
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 640, in install_pip
filter_stdout=_filter_setup)
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1006, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/rpsharp/local/...hon/bin/easy_install /usr/local/lib/pytho...pport/pip-1.1.tar.gz failed with error code 1

我尝试了此处提出的解决方案 https://stackoverflow.com/a/10538412/42897但它没有任何效果。

最佳答案

我在尝试运行 virtualenv 时遇到了同样的问题,发现 virtualenv 安装在/home/{user}/install/lib/python2.7/site-packages 而 python 指向/home/{user }/install/bin/virtualenv - 你应该通过运行来了解这一点

which virtualenv

所以我不得不卸载并重新安装 virtualenv

pip uninstall virtualenv 
pip install virtualenv

这对我有用。

关于python - 为什么 `virtualenv` 找不到 `pkg_resources` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10544067/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com