[英]Using virtualenv on Mac OS X
我一直在Ubuntu上使用virtualenv,但它运行起来很困难,因此我试图在Mac上使用它,但遇到了麻烦。
virtualenv
命令成功创建了目录,并且easy_install
很高兴在其中安装软件包,但是我无法导入安装的任何内容。 似乎sys.path
设置不正确:即使我使用--no-site-packages
选项,它也不包含虚拟site-packages
--no-site-packages
。 难道我做错了什么?
我在Mac OS 10.5.6上使用Python 2.5.1和virtualenv 1.3.3
编辑 :这是当我尝试使用virtualenv时发生的事情:
$ virtualenv test
New python executable in test/bin/python
Installing setuptools............done.
$ source test/bin/activate
(test)$ which python
/Users/Justin/test/bin/python
(test)$ which easy_install
/Users/Justin/test/bin/easy_install
(test)$ easy_install webcolors
[...]
Installed /Users/Justin/test/lib/python2.5/site-packages/webcolors-1.3-py2.5.egg
Processing dependencies for webcolors
Finished processing dependencies for webcolors
(test)$ python
[...]
>>> import webcolors
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named webcolors
>>> import sys
>>> print sys.path
['',
'/Library/Python/2.5/site-packages/SQLObject-0.10.2-py2.5.egg',
'/Library/Python/2.5/site-packages/FormEncode-1.0.1-py2.5.egg',
...,
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5',
'/Users/Justin/test/lib/python25.zip',
'/Users/Justin/test/lib/python2.5',
'/Users/Justin/test/lib/python2.5/plat-darwin',
'/Users/Justin/test/lib/python2.5/plat-mac',
'/Users/Justin/test/lib/python2.5/plat-mac/lib-scriptpackages',
'/Users/Justin/test/Extras/lib/python',
'/Users/Justin/test/lib/python2.5/lib-tk',
'/Users/Justin/test/lib/python2.5/lib-dynload',
'/Library/Python/2.5/site-packages',
'/Library/Python/2.5/site-packages/PIL']
编辑2 :使用activate_this.py
脚本有效,但运行source bin/activate
无效。 希望这有助于缩小问题范围?
相同的OS X / Python / virtualenv版本(OS X 10.5.6,Python 2.5.1,virtualenv 1.3.1)没有任何问题。
$ virtualenv test
New python executable in test/bin/python
Installing setuptools............done.
$ source test/bin/activate
(test)$ which python
/Users/dbr/test/bin/python
$ echo $PATH
/Users/dbr/test/bin:/usr/bin:[...]
$ python
[...]
>>> import sys
>>> print sys.path
['', '/Users/dbr/test/lib/python2.5/site-packages/setuptools-0.6c9-py2.5.egg',
要检查的一件事-在干净的外壳中运行以下命令:
$ virtualenv test
$ python
[...]
>>> import sys
>>> sys.path
['', '/Library/Python/2.5/site-packages/elementtree-1.2.7_20070827_preview-py2.5.egg'[...]
>>> sys.path.append("test/bin/")
>>> import activate_this
>>> sys.path
['/Users/dbr/test/lib/python2.5/site-packages/setuptools-0.6c9-py2.5.egg'
或从virtualenv文档中:
activate_this = '/path/to/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
那应该将当前的Python shell强制进入virtualenv
另外,在运行source test/bin/activate
尝试使用-v
标志(详细)运行python,它可能会产生一些有用的信息。
事实证明,我对virtualenv的问题是我自己的错:我已经将.bash_profile
配置为与PYTHONPATH
环境变量PYTHONPATH
,这导致了导入问题。
感谢所有花时间回答的人。 很抱歉没有自己进一步调查问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.