[英]Unable to find virtualenv or django after installing with pip
I installed virtualenv using pip and now receive the following error whenever I actually try and use it: 我使用pip安装了virtualenv,现在每次实际尝试使用它时,都会收到以下错误消息:
% virtualenv
Traceback (most recent call last):
File "/bin/virtualenv", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 2705, in <module>
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 668, in require
File "build/bdist.macosx-10.9-x86_64/egg/pkg_resources.py", line 571, in resolve
pkg_resources.DistributionNotFound: virtualenv==1.11.2
%
Similarly, I installed django with pip, and when I try and import django in python I get: ImportError: No module named django
. 类似地,我使用pip安装了django,当我尝试在python中导入django时,我得到了: ImportError: No module named django
。
I tried to install virtualenv again, this time using easy_install instead of pip. 我尝试再次安装virtualenv,这次使用easy_install而不是pip。 easy_install gave me an error saying that it was having issues with my PYTHONPATH
environment variable. easy_install给我一个错误,指出我的PYTHONPATH
环境变量有问题。 Lo and behold, after reading http://www.stereoplex.com/blog/understanding-imports-and-pythonpath , PYTHONPATH
is what python uses to find modules, and my PYTHONPATH
was unset. 瞧,看完http://www.stereoplex.com/blog/understanding-imports-and-pythonpath之后 , PYTHONPATH
是python用于查找模块的东西,而我的PYTHONPATH
未设置。
After setting PYTHONPATH
to /lib/python3.3/site-packages
(where pip was installing my modules), both virtualenv and importing django functioned properly. 将PYTHONPATH
设置为/lib/python3.3/site-packages
(在pip安装我的模块的位置)后,virtualenv和django导入均正常运行。
Note: because I have both python2.7 and python 3.3 installed, for me pip
actually installs packages to /lib/python2.7/site-packages
while pip3
installs packages to the aforementioned /lib/python3.3/site-packages
. 注意:因为我同时安装了python2.7和python 3.3,所以pip
实际上将软件包安装到/lib/python2.7/site-packages
而pip3
将软件包安装到上述/lib/python3.3/site-packages
。
For the unfamiliar, information on setting environment variables can be found here: https://help.ubuntu.com/community/EnvironmentVariables 对于不熟悉的人,可以在这里找到有关设置环境变量的信息: https : //help.ubuntu.com/community/EnvironmentVariables
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.