Mac OS X Lion上的Virtualenvwrapper错误

时间:2011-08-03 21:28:51

标签: python macos osx-lion virtualenv virtualenvwrapper

我刚刚将我的Mac从Snow Leopard更新为Lion。然后,我需要安装virtualenvvirtualenvwrapper。我用于easy_install。 我还将virtualenvwrapper设置添加到我的.bash_profile文件中,如下所示:

# 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 :(得分:13)

由于/Library/Frameworks/Python.framework/Versions/2.7/bin/python是单独安装的Python 2.7(可能来自python.org安装程序)而不是Apple提供的Python 2.7(/usr/bin/python2.7)的路径,因此您需要确保正在使用easy_install用于单独的Python或更改为使用Apple提供的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

答案 1 :(得分:0)

我遇到了类似的问题,我通过将$ TMPDIR导出到更好的路径来解决它,而不是Mac OS X喜欢的随机垃圾。

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

$ source .env

现在virtualenvwrapper可以创建临时文件了。简而言之,只需将export TMP=/tmp/whatever添加到shell运行时配置文件中(例如,对于ZSH,它是~/.zsh,对于bash,它是~/.bashrc)。