Mac OS X Lion上的Virtualenvwrapper错误

8 投票
2 回答
4419 浏览
提问于 2025-04-16 22:50

我刚把我的Mac从Snow Leopard升级到了Lion。然后我需要安装virtualenvvirtualenvwrapper。我用easy_install来安装这两个东西。

我还在我的.bash_profile文件里添加了virtualenvwrapper的设置,内容如下:

# virtualenvwrapper settings
export WORKON_HOME="~/virtualenvs"
source "/usr/local/bin/virtualenvwrapper.sh"

但是当我尝试加载这个文件时,出现了以下错误:

ERROR: Could not create temporary file name. Make sure TMPDIR is set.
virtualenvwrapper.sh: There was a problem running the initialization hooks. 
If Python could not import the module virtualenvwrapper.hook_loader, 
check that virtualenv has been installed for VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/2.7/bin/python and that PATH is set properly.

谢谢大家的帮助。

2 个回答

0

我遇到过类似的问题,我是通过把 $TMPDIR 设置成一个更合理的路径来解决的,而不是让 Mac OS X 随便选一个乱七八糟的地方。

$ grep TMPDIR ~/.env
export TMPDIR=/tmp/

$ source .env

现在 virtualenvwrapper 可以正常创建它的临时文件了。简单来说,只需要在你的终端配置文件里加上 export TMP=/tmp/whatever 这行代码就行了(比如,如果你用的是 ZSH,那就是 ~/.zsh,如果是 bash,那就是 ~/.bashrc)。

13

因为 /Library/Frameworks/Python.framework/Versions/2.7/bin/python 是一个单独安装的 Python 2.7 的路径(可能是通过 python.org 的安装程序安装的),而不是苹果自带的 Python 2.7 (/usr/bin/python2.7),所以你需要确保使用的是这个单独的 Python 的 easy_install,或者换成使用苹果自带的 Python。要做到这两点,你需要确保你的 shell 的 PATH 变量设置正确。对于第一种情况,你可以通过以下方式安装 easy_install

cd /tmp
curl -O http://python-distribute.org/distribute_setup.py
sudo $VIRTUALENVWRAPPER_PYTHON distribute_setup.py

你可以调整你的 shell PATH,让它包含框架的 bin 目录。如果你使用的是 bash,一种方法是在 ~/.bash_profile 文件中添加这一行:

export PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

然后打开一个新的终端会话。现在你应该能发现你刚安装的 easy_install 是正确的:

$ which easy_install
/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install

撰写回答