This post describes how to install IPython on a Mac OS X, Mountain Lion. Step by step, it explains how to install Python, Homebrew, Virtualenv, IPython, IPython Notebook and some useful libraries like Matplotlib.
Mac OS X comes with Python 2.7 already installed, that can be used for learning but which might be out of date. Therefore, in this post we will explain how to install the real version of Python as well, which is better for developing.
Go to the Apple Store and download the free version of XCode.
Once installed, launch the application from the Launchpad menu.
In the upper menu go to Xcode –> preferences…, or alternatively use the shortcut cmd+, .
Once in the preferences window go to the Downloads tab and install the Command Line Tools, which is in the Components section. To install it you just need to click in the right arrow.
To download and install Homebrew you need to run the following command in the Terminal:
$ ruby -e “$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)”
Install Python 2.7
Now it’s very easy to install Python! just write the following in your Terminal:
$ brew install python
Unfortunately, when we run python on the Terminal, we will still be using the preinstalled Python that comes with Mac OS X. We need to change the path to point to the new version of Python.
Open (or create if you don’t have it yet) the file ~/.profile and write the following lines in it:
The good thing about installing Python with Homebrew is that you also install pip and Distribute, which extend the packaging and installation facilities provided by the distutils in the standard library.
A good practice is to use a virtual environment to have all the packages that you are using for one project in the same folder. It is more easy to share and maintain.
To install Virtualenv:
$ sudo pip install virtualenv
Let us create a new virtual enviroment, called envipython
$ virtualenv envipython
which will create the folder envipython. To activate this environment:
$ source envipython/bin/activate
Note that the command line has changed to somehting like (envipython)$.
From now on, we will install the packages using this virtual environment. If you don’t want to use a virtual environment, you can install them in your machine with the same command lines.
Install IPython and IPython Notebook
$ pip install ipython
IPython comes with a very nice web-based notebook environment, which allows you to run python scripts in a similar way as with Mathematica or Matlab.
To install it, you will need to add the following libraries:
$ brew install freetype
$ brew install libpng
$ pip install readline
$ pip install tornado
$ brew install zeromq –universal
$ pip install pyzmq
$ pip install pygments
$ brew install pyqt
$ pip install jinja2
And that’s it! To run your IPython Notebook you only need:
$ ipython notebook
In : from IPython.external.mathjax import install_mathjax
In : install_mathjax()
Optional Science Packages
$ pip install numpy
$ pip install scipy
For Matplotlib you also have to install the library pkg-config (which in my case, it was already installed). Moreover, you might want to install ffmpeg, which allows to save movies using matplotlib.animation library.
$ brew install pkg-config
$ brew install ffmpeg
$ pip install matplotlib
Whohaaa!! that was a little bit of installation!?! Hope it also worked for you! 🙂
Marina Mele has experience in artificial intelligence implementation and has led tech teams for over a decade. On her personal blog (marinamele.com), she writes about personal growth, family values, AI, and other topics she’s passionate about. Marina also publishes a weekly AI newsletter featuring the latest advancements and innovations in the field (marinamele.substack.com)