Getting a python virtual env error after installing Lion Getting a python virtual env error after installing Lion python python

Getting a python virtual env error after installing Lion


I am a complete Python/Virtualenv novice. However, I had the exact same problem and found a solution that worked for me. I believe that this will vary greatly depending upon the way you originally setup Python & Virtualenv.

In my case, the Lion upgrade completely wiped out all contents of my /Library/Python/2.*/site-packages, but left the now broken executables (which link to the contents of this folder) in /usr/local/bin. I believe that this is the root cause of the cryptic "No module" import errors.

Reviewing my .bash_history, I had originally used easy_install to install pip, and then pip to install virtualenv and virtualenvwrapper. Once I repeated these steps, then I was able to re-enter my old virtual environments which still contained all the packages I had installed on 10.6. Note, however, that 10.6 shipped with Python 2.6 as default. If your packages require Python 2.6, you should change your default Python version to 2.6 first.

Step-by-step:

  1. I removed old Virtualenv configuration commands from my shell startup scripts (eg., .bash_profile). Start a new terminal session.
  2. (optional) Choose the version of Python you wish to use, eg.,
    defaults write com.apple.versioner.python Version 2.6
  3. sudo easy_install pip. It seems as though /Library/Python/2.*/site-packages now requires administrator privileges. I don't recall that being the case in 10.6 (or at least my bash history doesn't reflect that).
  4. sudo pip install virtualenv
  5. sudo pip install virtualenvwrapper
  6. Finally, I re-enabled those virtualenv configuration commands I disabled in step 1. A new terminal session had everything back the way it was (look at pip freeze -l to see local packages in this virtual environment). I think.


My solution on Ubuntu 14.04 where I had installed python3.4 was to add this to the ~/.bashrc file so that the tail of it looked liked this:

#Setup virtual envwrapper for python in case default doesn't workVIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.4export VIRTUALENVWRAPPER_PYTHON# needed for virtualenvwrapperexport WORKON_HOME=$HOME/.virtualenvsexport PROJECT_HOME=$HOME/projectssource /usr/local/bin/virtualenvwrapper.sh

When I did pip freeze on regular python which was 2.7 it showed packages installed correctly but still complained. Even though it complained the virtualenv did work.

I have later removed the errors by making sure that all the files in the ~/.virtualenvs belong to the user and group rather than a smattering of them to root. Like this:

bashcd ~sudo chown -R ubuntu:ubuntu .virtualenvs


Have you installed virtualenv for the Python that you are using? If you are using the default Apple-supplied system Python 2.7, it doesn't come with the virtualenv package pre-installed. Use /usr/bin/easy_install to install it.

UPDATE: Just to be clear, on Lion 10.7, there is now an Apple-supplied Python 2.7 which is the default version when you use /usr/bin/python. Apple continues to also ship a Python 2.6 and a 2.5 in Lion as it did in 10.6 Snow Leopard. You can pick which version you want by explicitly referencing it, as in /usr/bin/python2.7, /usr/bin/python2.6, etc, and you can change the default that /usr/bin/python uses; read the Apple man page (man python) for details. The key point, though, is that, in general, Python packages are installed to a specific version. If you installed something for 2.6, you'll need to install it with python2.7 (or easy_install-2.7) if you want to use it with 2.7.