Virtualenvwrapper errors on Mac OS X Lion
Asked Answered
S

2

8

I have just update my Mac from Snow Leopard to Lion. I then needed to install virtualenv and virtualenvwrapper. I used for both easy_install. I also added virtualenvwrapper settings to my .bash_profile file as following:

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

But when sourcing it I get the following error:

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.

Thank you all for your help.

Saire answered 3/8, 2011 at 21:28 Comment(0)
C
13

Since /Library/Frameworks/Python.framework/Versions/2.7/bin/python is the path to a separately-installed Python 2.7 (possibly from a python.org installer) rather than the Apple-supplied Python 2.7 (/usr/bin/python2.7), you need to make sure you are using an easy_install for that separate Python or change to using the Apple-supplied Python. To do either one, you should ensure that your shell PATH variable is correct. For the first case, you should be able to install an easy_install by doing the following:

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

You can fix up your shell PATH to include the framework bin directory. If you are using bash, one way would be to add this line to ~/.bash_profile:

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

Then open a new Terminal session. You should now find that easy_install you just installed is the right one:

$ which easy_install
/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install
Carloscarlota answered 3/8, 2011 at 21:58 Comment(4)
Hi Ned "The Python Man" Deily! Thanks really a lot for your answer. After your answer I thought about that probably I had also to update my Python installation before looking for help. So, that done, on my iMac everyithing worked as expected, while on my Macbook not… :( I, then, followed your words of wisdom and fixed it. Really, really thank you. Fyi, both easy_install then pip were in /usr/local/bin/. After your directions they are in my $VIRTUALENVWRAPPER_PYTHON (that, btw, I already have it added to my $PATH in my .bash_profile file). So, what exaclty distribute_setup.py did? tnxSaire
The easiest way to think about is that each instance of Python has to have its own easy_install commnad. The distribute_setup.py script installs a version of easy_install for the Python instance that it is running under.Carloscarlota
Thanks again. Hopefully with virtualenv in place I should now be able to update to major Python version directly in a virtual environments and to manage specific libraries with other ones. Being just learning Python, I am sure we'll meet again, thanks in advance for your invaluable help.Saire
I had the problem the other way round: I have my Python installed using homebrew (which creates a symlink in /usr/local/bin), but the export PATH="/Library/Frameworks/...:${PATH}" in ~/.bash_profile broke things. Commenting out that line fixed everything.Halfback
C
0

I had a similar problem and I solved it by exporting $TMPDIR to a saner path, rather than the random crap that Mac OS X prefers.

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

$ source .env

and now virtualenvwrapper can create its temporary files fine. To make the long story short, just add export TMP=/tmp/whatever to your shell runtime configuration file (for example, for ZSH it is ~/.zsh, for bash it is ~/.bashrc).

Caboodle answered 4/8, 2011 at 11:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.