Learning how to install python packages
In an earlier post I described my python setup for Debian, this time I’ve kept notes while working yesterday to get a stable python environment on Mac OS X Mountain Lion (10.8.1). I’ve used the notes to write up the steps that worked, there were a lot of dead ends along the way that I haven’t included.
Since the upgrade to Mountain Lion, I’ve had a lot of problems with my python environment not working, and in trying to sort it out I’d somehow managed to end up with a broken easy_install. I think I achieved that by downloading and installing the latest command line tools from the Apple Developer website instead of through XCode. So I’d recommend sticking with the one installed through XCode. But at that stage I wasn’t taking notes about what I was trying, so I’m not sure.
I fixed easy_install by installing distribute:
|
1 2 |
curl -O http://python-distribute.org/distribute_setup.py sudo python distribute_setup.py |
I noticed that my path had /usr/bin ahead of /usr/local/bin, but this should probably be the other way around.
|
1 |
/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/texbin: |
This is being set by /etc/paths  and the ~/.bashrc
Changed /etc/paths to have:
|
1 |
/usr/local/git/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/X11/bin:/usr/texbin |
Then started setting up my ipython, scipy and pandas environment. Using “distribute” in the virtual environment seems to work better at building some packages.
|
1 2 3 4 5 |
mkvirtualenv --distribute brmTest2 pip install tornado pip install ipython pip install numpy pip install scipy |
The scipy install failed, and I fixed it by installing the dev version as suggested here – http://www.thisisthegreenroom.com/2012/compiling-scipy-on-mountain-lion/
|
1 2 3 |
pip install -e git+https://github.com/scipy/scipy#egg=scipy-dev pip install pandas pip install matplotlib |
The matplotlib install failed, so I then followed these instructions -
https://gist.github.com/1860902Â (but not step 5) to install X11 and pkg-config as follows:
download and install X11 from
|
1 2 |
http://xquartz.macosforge.org/trac/wiki sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer |
logged out and in to activate X11.
|
1 |
brew install pkg-config |
(not sure this actually helped)
The x11 libraries are not on the path (which I thought was what pkg-config was meant to fix?) Fixed by using:
|
1 |
export CFLAGS="-I/usr/X11/include -I/usr/X11/include/freetype2 -I/usr/X11/include/libpng12" |
then
|
1 2 |
pip install matplotlib pip install pyzmq |
So I now have a virtual environment with the right Python packages installed, and I understand a bit more about working out how to install packages when they fail. I still need to work out what the difference is between pip, distribute and easy_install.


