In a recent post, I tried to explain how to install scientific python libraries on OSX and get rid of the most common errors. In that case everythong I did was for python 2.7.

Yesterday I decided to fully move to python 3.4. I’ve removed my python installation via homebrew and with it all the installed packages.

Moving to python 3 is straightforward if you have done the procedure described in my previous post, it all really reduces to replace every occurrence of python in that post with python3 and every occurrence of pip with pip3.

Assuming that you had installed homebrew, fortran and pkg-config as explained there, what you have to do is just type and exectute the following:

    brew install python3
    pip3 install numpy
    pip3 install scipy
    pip3 install matplotlib

And for qutip you just do

    pip3 install cython
    pip3 install qutip

# A better IPython

In the last post we installed ipython with a minimal working configuration. Recently I started enjoying writing my simulation with the notebooks of iJulia (we will discuss it soon) and iPython: two very nice web based environment to write (and execute) your code.

To run the iPython notebook one should type

    ipython notebook

or, if using python 3,

    ipython3 notebook

If you try to do it, your should get some errors. Luckily these are very easily solved installing the following packages (if you use python 2 replace pip3 with pip):

    brew install libzmq
    pip3 install pyzmq jinja2

If you now run, let’s say, ipython3 notebook, after a moment you should see a new browser window with your notebook.


# Julia for fast computations

Julia is a recent “high-level, high-performance dynamic programming language for technical computing” developed as an open source project at MIT. It is extremely fast and powerful but as readable as python (if not more).

It can nicely and simply interface with C, Fortran and Python and is bloody fast.

I’ve been using it for the exercises of NLP in coursera and some simulations and I really enjoy it.

To install julia you have few alternatives. You can grab a binary precompiled installer from the official website, install the nice (open source and free) IDE Julia Studio or use homebrew (my first choice):

    brew tap staticfloat/julia
    brew install --64bit julia

If you get errors, or you want to install the support for gnuplot plots, I redirect you to the github page of hoembrew-julia, where you can find all the additional information you may need.

After having installed julia, open a terminal and run julia or open Julia Studio, and have fun!

There are many resources to learn coding in julia. If you don’t want to read the full docs (they are pretty short, is not a big deal) you can use the resources linked at the Teaching Julia page, in particular you may find easy to start with Julia Tutorial, with Learn X in Y minutes or with the series of Julia Studio tutorials.

After you played a bit with it. The time to install some packages arrives. The most important, imho, is IJulia. A kernel for IPython that lets you write your julia code in a ipython notebook. Inside the julia environment (namely, after having opened a terminal and run julia) execute the following

    julia> Pkg.add("IJulia")

This will download IJulia and a few other prerequisites, and will set up a Julia profile for IPython.

Notice that julia> is julia’s shell prompt, you don’t have to type it. It must be already there after you run julia.

To use IJulia you just need to run

    ipython3 notebook --profile julia

and eventually make an alias out of it if you plan to use it often. A simple IJulia tutorial from the MIT can be found on IPython website.

Additionally you may want to install Plots, PyPlot, Winston or some other package for plots.

To understand how to make complex plots with matplotlib using julia’s pyplot interface I’ve found the following post extremely useful: Naval Warfare with JuMP + Julia.