Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Quick virtualenv fix on Mountain Lion

Quick virtualenv fix on Mountain Lion


It appears that Apple somehow broke Python in Mountain Lion, so even with the latest Command Line Tools and Xcode 4.4 virtualenv won't properly work. During virtual environment creation it will try to install easy_install inside /Library hierarchy. So let's give it a quick workaround. Let's install custom python into your $HOME-directory using pythonbrew!

Installing proper Command Line Tools

Without the Apple Mac Developer account you won't even see the proper download link for the latest CL Tools and the old one won't work on ML. So here's the link: It points towards the Apple website so don't worry.

Let's try pythonbrew

Next we will install pythonbrew: curl -kL | bash

After that we need to put pythonbrew's bin/ directory before anything else in your $PATH. Add this line to the end of your .bashrc file: [[ -s $HOME/.pythonbrew/etc/bashrc ]] && source $HOME/.pythonbrew/etc/bashrc

Source your new .bashrc: source ~/.bashrc (or reopen your terminal) and we are ready to install our custom python.

Install desired python

With pythonbrew we can have multiple versions of python interpreters installed at the same time and conveniently switch between them. Let's install 2.7.2: pythonbrew install 2.7.2

The compilation is done in the background and can take a while. You can view the build log using tail -f $HOME/.pythonbrew/log/build.log

After successful installation you need to switch your pythonbrew's python version to 2.7.2: pythonbrew switch 2.7.2

Finally, working virtualenv

pip is already installed here, so all you need is to fire pip install virtualenv and you are good to go.

This tool will install virtualenv & virtualenvwrapper with one command:

I'm on 10.8 and the command line package is telling me it's only for 10.7.


I'm on 10.8 and the command line package is telling me it's only for 10.7.

What is your CL package filename?

Have you tried the developer preview CL tools (Preview 3). They have worked for me and you don't need a Mac OS developer subscription, but you may need a free developer account . Get them here:


There are new (Late July) CL tools released today, they will do too.

Ahh, I haven't seen those yet. Thanks

jiaaro commented Jul 26, 2012

Finally got this working by installing the Command line tools via xcode:

You need to install Xcode 4.4 (from the app store) and then, within xcode open Xcode > Preferences (or press Cmd + ,) then open the downloads tab and install the Command Line Tools.


@thesharp I had the same issue with it saying it was only for 10.7. If you upgrade to xcode 4.4 and download from the download preference pane, it downloads successfully. Unfortunately, my python environment is still pretty messed up.


I actually just got everything working. I've seen lots of people complaining about different issues. For me I was having trouble running python specific packages. It seems that mountain lion did something to pip and it's packages. Thankfully I don't have too many of them. I had to sudo easy_install pip (not sure why I needed sudo). Then I used pip to re-install broken packages. Things appear to be working right now.

I should point out that installing Mountain Lion wipes your site-packages folder completly so you need to reinstall all of your packages using Pip. Also I found it much easier to destroy all of my virtualenv environments and rebuild them from requirements files.

zvikico commented Sep 19, 2012

For those looking for a quick solution - downloading and installing the latest 2.7.x python from solved the problem. Make sure you reboot your machine after the installation is complete, otherwise nothing will work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment