For those unfamiliar, iPython is a great interactive console for Python. I’ve found it very useful for data processing and while developing apps.
I particularly appreciate the new qtconsole, which allows you to use a somewhat more user-friendly qt based terminal instead of the system terminal.
On mac however i was continuously bugged by the need to launch ipython from the terminal even if i wanted to use the qtconsole only. So i made a tiny little applescript which i’ve found very useful. Here it is:
set dest to POSIX path of (choose folder)
do shell script "cd " & dest & " ; /Library/Frameworks/Python.framework/Versions/7.2/bin/ipython qtconsole --pylab"
If you’re unfamiliar with Applescript there are plenty of tutorials out there. In brief, you just need to launch the applescript editor and paste the above code as a new project, then save the script as an application (choose the right option in the save dialoge) to your Applications folder. IPython will then be available just like any application.
A couple of things to note:
I added a magic line to the command – the first line opens up a Mac file dialogue. I’ve found this is the best way to start iPython on the correct path – just select the folder where your scripts are. The dialogue will show up at every launch BUT it will remember what folder you were in last time so you don’t have to navigate to the folder every time, just hit enter.
You will also have to edit the path to match your iPython path. Mine is in /Library/Frameworks/Python.framework/Versions/7.2/bin/ipython because I’m using the excellent Enthought Python distribution (EPD) instead of the apple default. I also include the –pylab flag to automatically load matplotlib’s pylab.
Important! This script ONLY works for the qtconsole, since it doesn’t open a terminal the regular ipython won’t show up. To use the qtconsole you will need the appropriate dependencies installed. If you are using EPD complete package everything is included.
If you are using EPD free or Mac default python or python.org python you will need a few things – which can be a bit of a pain to install on Mac if you’re unsure of what you’re doing.
- PyQT or PySide qt python bindings. I recommend PySide which has an installer on their site and is generally less of a pain to install than pyqt.
Python ZermoMQ. This is more annoying to install yourself, because you have to install zeromq, then the python bindings. If you’re on Snow Leopard or Lion you could run into problems where the OS is 64 bit but your python is in 32bit, depending on your python setup. You can try easy_install or pip, but this didn’t work for me because the included binaries didn’t like my 32/64 bit mixup. I ended up installing Homebrew then doing
brew install zeromq --universal
this will get you 32 and 64 bit. You then need to install pyzmq using pip install pyzeromq supplying it with the zeromq path like this:
pip install pyzmq --zmq=/usr/local/Cellar/zermomq
- Finally, you’ll need matplotlib, numpy and scipy, which either come with EPD package or can be installed from their respective home pages or through PyPi
Finally, your milage my vary, i did all this a while ago and some instructions may have errors or be out of date. Hopefully this should give you a pointer though, good luck!