Every time I complete a huge project, I take a look at the state of my file system and promptly bang my head against my desk. I have a horrible habit of downloading software I think will be extremely useful and it turns out to be junk. Over the years I have learned that starting with a clean state works best if I don’t have anything else huge in line.
In the past couple weeks stumbled into this situation yet again. This happened about the time a few colleagues and I were discussing how we prepare our python working environments and how there is a lack of solid walkthrough of a mac setup. The result of the exchange is the following step-by-step guide for working environment.
My Must Have components:
- Homebrew Cask
- Python (2.X and 3.X)
- Optional Python Packages
NOTE: My system is a Mac running Mavericks 10.9.2 for this tutorial, though it will probably work just fine on 10.7 and up.
Way I like this setup:
For every developer that uses virtenv to manage their python setup effectively I hear twice as many say they use it but don’t quite understand why. The long and short of this method is it creates multiple virtual machines for your terminal; i.e. you can set parameters for one envelope that can ignored by the rest of your system. This is great if you are testing your code for a variety of situations, but in my case I just want my code to function.
For me this is where homebrew enters the picture. It is a software manager that allows you to make and install your software in individual directories while creating symbolic links to a central location. The benefit is you can keep all of your software up-to-date with a single command. I also use an extension of this called homebrew-cask, which we will install here. Complete descriptions of each can be found on their github sites.
Since I am setting up my environment on a fresh install, I need to first get the xcode command line tools up and running. In a terminal window (access it using “command” + ”space” and type in terminal followed by return), type:
$ sudo xcodebuild –license
You will be asked for your system password, so plug that in and approve the pop-up that appears. It may take a few minutes to download and install the package, so be patient.
Lets get the progam using:
$ ruby -e "$(curl –fsSL https://raw.github.com/Homebrew/hombrew/go/install)”
The developers of the package have done an excellent job on creating informative terminal output; so you will see lots of information scroll down the terminal screen. Once installed, it is important to both update your brew and make sure the initial symblinks a functioning correctly. We can do that with the following two commands:
$ brew update $ brew doctor
After running brew doctor, you should see “Your system is ready to brew.” If you receive error messages, the program will give you action steps to fix the problems.
$ brew tap caskroom/cask $ brew install brew-cask
I am a big fan of Firefox, and conveniently there is a cask to install the program for me!
$ brew cask install firefox
I use both python 2.7.x and 3.x regularly, thus I the versions installed in parallel.
While Mac OS generally comes with 2.7 it never hurts to make sure it has the latest release. Homebrew works nicely for this:
$ brew install python
Likewise, you can brew 3.x:
$ brew install python3
The next few packages can be compiled for 2.7.x and 3.x in unison. Please note numpy must be install prior to scipy, so let’s knock that out.
$ brew tap Homebrew/python $ brew install numpy --with-python3
Scipy and Zeromq
$ brew install scipy --with-python3 $ brew install zeromq --with-python3
In each of these steps you will see multiple “pours” (aka downloads for the non-drinkers in the crowd). These are additional dependencies built into the packages.
Pip (minimal use)
I found not everything has a brew or a cask available, so I have to resort to easy install and pip. I for one hate having repeating myself, even when it is just typing ‘sudo’ before commands. To remedy this, you can temporarily bypass it using:
$ sudo –i
Then enter your password. The catch is you want exit out after you are done with an install session! Power is good, but too much power is lethal.
$ easy_install pip $ easy_install pip3
Jinja, Tornado, Pymzq and Matplotlib
$ pip install jinja2, tornado, pyzmq, matplotlib $ pip3 install jinja2, tornado, pyzmq, matplotlib
$ ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pandas $ pip3 install pandas
$ pip install ipython $ pip3 install ipython
As noted before, sudo -i makes installation less annoying by giving you administrator privileges. Now that you have your software installed, you should re-activate your protective layer:
Firing up a notebook:
$ ipython notebook
For a python 3.x notebook:
$ ipython3 notebook
Now your system is ready for action! Hopefully this guide will serve as a quick one-stop-shop for mac users looking to setup both Ipython notebook using 2.7.x and/or 3.x.