IPython is a very powerful and convenient Python console (alternative to standard Python interpreter) that makes every day tasks much easier. It also plays well with scientific libraries such as numpy and matplotlib making it the console of choice for almost every scientist.
The current version of IPython frontend (version 0.12) comes in three flavours:
- standard text-based interpreter with line editing capabilities (including tab completion) that works in every terminal (for example Terminal.app in MacOSX),
- Qt console for more advanced editing (for example, multiline editing and embedding of graphical output) and multiple tabs,
- web-based notebook — this is a very recent frontend which allows one to run Mathematica-like notebook in a browser — great for demos and scripting.
I like having a copy of IPython Qt console running all the time for simple calculations or checking the docstrings when I program (normally I code in Vim and I do not use call tips). In order to make IPython quickly accessible it is convenient to put an IPython luncher in MacOSX Dock. A nice feature of Dock is that when you want to find a running instance of any application, you may simple click on its icon and if the window already exist it will be brought to the foreground.
Unfortunately, creating a Dock luncher for IPython is not easy. Basically, you have to create a new bundle (file-like directory) that contains all the application data. Here is the entire process step-by-step:
- First, you need to install IPython. I will use as an example Macport’s ipython, but after adapting some paths the procedure should work with any installation.
- In Finder create a directory named
IPythonQt.app. This will create a new bundle which is a special directory that contains application and all the related files. In order to open the directory, right-click the directory and select “Show package contents” (alternatively you may “cd” to the directory in your terminal). Create the following tree inside the directory:
Contents MacOS Resources
- Using any text editor (such as Vim) create a new file with the same name as the package (without
.appsuffix, in our case
IPythonQt) and the following contents:
#!/opt/local/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python import os executable = '/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/ipython' arguments = [executable, 'qtconsole', '--pylab'] os.environ["PYTHONPATH"]=os.getenv("PYTHONPATH", "") os.execve(executable, arguments, os.environ)
Change the paths at the top of the file and in
executablevariable to the paths of your python and ipython interpreter, respectively (you may check them in the terminal using
Add the “executable” bit to the file and copy it to
MacOSsubdirectory of IPythonQt package created in the previous step:
chmod +x IPythonQt cp IPythonQt IPythonQt.app/Contents/MacOS
- If you also want to add an icon, you have to copy the icon
.icnsfile (to be downloaded here, right click – Save As…) to the Resources subdirectory and add the following
Info.plistfile to the
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleIconFile</key> <string>ipython_icon</string> </dict> </plist>
At the end your package should look like this:
Contents MacOS IPythonQt Resources ipython_icon.icns Info.plist
- If you double click on the directory in Finder an IPython Qt console should be opened. You can also copy the package to the Applications directory and drag it to your Dock so that it is always at hand. When you activate the luncher, a small dot will appear under the icon, which means that IPython is already open. Double-clicking the icon will bring the open window to the foreground.I hope that was helpful! If you have any questions please leave a comment below.