Thursday 17 October 2013

Mac OS X, Python, PySide and Matplotlib

In these days I'm working on Python application for manage some metereological datas. It uses PySide for the GUI and Matplotlib to plot some useful charts. Unluckily, I had some troubles to add this last library. After some work, I found a solution. This post is a brief guide to my little oddity on using PySide and Matplotlib on a Mac OS X environment.

Install homebrew

Follow homebrew installation instruction from its official site. Basically just type in your terminal
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

Install python

It's easy with homebrew. Just type
brew install python

Set PATH

Set your Python Path. Write on your .bash_profile
export PATH=/usr/local/share/python:$PATH
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

Install virtualenv

I know, probably you don't want to do 'cause you want just ONE python. I am with you, but it seems quite hard to do on Mac OS X. So, be patient!
pip install virtualenv

Create a virtualenv

I put my virtualenv in the same directory of my project. Probably it's redundant, but it's specific for this project.
cd fooproject
virtualenv py27 --distribute
A new directory called py27 will be created. It will contain all python libraries. Now, let's activate our new virtualenv
source py27/bin/activate
Your shell will become something like this:
(py27)darkstar: fooproject username$

Install PySide and PySide Tools

For some unclear reasons, pip can't install pyside: it can't find . I resolved using brew again and installing also pyside-tools to use it in with QT Designer. I did it staying in virtualenv
brew install pyside pyside-tools

Install GFortran

NumPy require GFortran. So add it with brew
brew install gfortran

Install matplotlib

Always in virtualenv, I installed matplotlib and numpy
pip install numpy matplotlib

Conclusion

Program and install your packages always from your virtualenv. When you're tired of it, just type
deactivate
And you'll exit. Good luck: I had many problems with this stuff!

No comments: