Create a gist now

Instantly share code, notes, and snippets.

Embed
Quick virtualenv fix on Mountain Lion

Quick virtualenv fix on Mountain Lion

Overview

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: http://goo.gl/iBTXh. It points towards the Apple website so don't worry.

Let's try pythonbrew

Next we will install pythonbrew: curl -kL http://xrl.us/pythonbrewinstall | 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.

@brainsik

This comment has been minimized.

Show comment
Hide comment
@brainsik

brainsik Jul 25, 2012

This tool will install virtualenv & virtualenvwrapper with one command:

https://github.com/brainsik/virtualenv-burrito#readme

This tool will install virtualenv & virtualenvwrapper with one command:

https://github.com/brainsik/virtualenv-burrito#readme

@Buzzingrobot

This comment has been minimized.

Show comment
Hide comment
@Buzzingrobot

Buzzingrobot Jul 26, 2012

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.

@thesharp

This comment has been minimized.

Show comment
Hide comment
@thesharp

thesharp Jul 26, 2012

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?

Owner

thesharp commented Jul 26, 2012

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?

@thomaspurchas

This comment has been minimized.

Show comment
Hide comment
@thomaspurchas

thomaspurchas Jul 26, 2012

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: https://developer.apple.com/downloads/

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: https://developer.apple.com/downloads/

@thesharp

This comment has been minimized.

Show comment
Hide comment
@thesharp

thesharp Jul 26, 2012

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

Owner

thesharp commented Jul 26, 2012

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

@thomaspurchas

This comment has been minimized.

Show comment
Hide comment
@thomaspurchas

thomaspurchas Jul 26, 2012

Ahh, I haven't seen those yet. Thanks

Ahh, I haven't seen those yet. Thanks

@jiaaro

This comment has been minimized.

Show comment
Hide comment
@jiaaro

jiaaro 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.

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

This comment has been minimized.

Show comment
Hide comment
@thesharp

thesharp Jul 26, 2012

Owner

thesharp commented Jul 26, 2012

@adamgotterer

This comment has been minimized.

Show comment
Hide comment
@adamgotterer

adamgotterer Jul 26, 2012

@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.

@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.

@thesharp

This comment has been minimized.

Show comment
Hide comment
@thesharp

thesharp Jul 26, 2012

Owner

thesharp commented Jul 26, 2012

@adamgotterer

This comment has been minimized.

Show comment
Hide comment
@adamgotterer

adamgotterer Jul 26, 2012

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 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.

@thomaspurchas

This comment has been minimized.

Show comment
Hide comment
@thomaspurchas

thomaspurchas Jul 26, 2012

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.

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.

@thesharp

This comment has been minimized.

Show comment
Hide comment
@thesharp

thesharp Jul 26, 2012

Owner

thesharp commented Jul 26, 2012

@zvikico

This comment has been minimized.

Show comment
Hide comment
@zvikico

zvikico Sep 19, 2012

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

zvikico commented Sep 19, 2012

For those looking for a quick solution - downloading and installing the latest 2.7.x python from python.org 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