2011-08-03 176 views
8

我剛剛將Snow Leopard更新到Lion。然後我需要安裝virtualenvvirtualenvwrapper。我用於兩個easy_install。 我還添加virtualenvwrapper設置我的.bash_profile文件如下:Mac OS X Lion上的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. 

感謝大家的幫助。

回答

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路徑包括框架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 
+0

嗨Ned「蟒蛇人」Deily!非常感謝你的回答。 在你的回答之後,我想到了可能在查找幫助之前,我還需要更新我的Python安裝。所以,這樣做,在我的iMac全能工作如預期,而在我的MacBook不... ... :( 我,然後,你跟着你的智慧和固定它的話真的,真的很感謝你。 '/ usr/local/bin /'。在你的指令之後,它們在我的'$ VIRTUALENVWRAPPER_PYTHON'中(也就是說,我已經將它添加到我的'.bash_profile'文件中的'$ PATH') exaclty'distribute_setup.py' does?tnx –

+0

最簡單的思考方式是每個Python實例都必須有自己的'easy_install' commnad。'distribute_setup.py'腳本爲Python實例安裝一個'easy_install'版本它正在運行。 –

+0

再次感謝。希望能夠使用'virtualenv',我現在應該能夠在虛擬環境中直接更新到主要的Python版本,並且可以使用其他版本管理特定的庫。 作爲剛剛學習Python,我相信我們會再次見面,在此先感謝您的寶貴幫助。 –

0

我也有類似的問題,我通過導出$ TMPDIR一個理智的路徑,而不是隨機的廢話是Mac OS X的喜歡解決它。

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

$ source .env 

現在virtualenvwrapper可以創建它的臨時文件。爲了長話短說,只需將export TMP=/tmp/whatever添加到您的shell運行時配置文件(例如,對於ZSH,它是~/.zsh,對於bash它是~/.bashrc)。