【发布时间】:2009-05-09 15:53:02
【问题描述】:
我一直在 Ubuntu 上使用 virtualenv,但它很糟糕,所以我尝试在我的 Mac 上使用它,但遇到了问题。
virtualenv 命令成功创建目录,easy_install 很乐意在其中安装软件包,但我无法导入我安装的任何内容。似乎sys.path 设置不正确:它不包括虚拟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 无效。希望这有助于缩小问题范围?
【问题讨论】:
-
您在该解释器中获得的 Python 路径是什么(例如 sys.path 的值)?没有它就很难知道从哪里开始调试。
-
你说得对,我应该把它包括在内。我剪掉的路径部分只是更多的鸡蛋文件。
标签: python macos virtualenv