:Title:
:Date: 4/21/2012
Introduction
I found a good online tutorial around Installing Python, virtualenv,
NumPy, SciPy, matplotlib and IPython on
Lion,…
well, mostly…. There are a couple fundamental differences between wat I
do and what I will call the “green room” installation:\
- XCode no longer comes with Command Line Utilities, so if you just
start pushing forward on installing without these utilities, things
won’t work (so that’s been added). - After installing Homebrew, you will get some messages that indicate
there is a little bit more to do - SciPy has updated so you can now
$ pip install scipy
pretty easily - Python has updated to 2.7.3 since the “green room” tutorial, so some
of the file paths are slightly different - And lastly, what’s quantitative development in Finance without
Pandas so that’s been added to the installation - Lastly, it’s always important to have testing commands to ensure
that libraries mostly installed correctly, so I’ve added that to the
end of the instructional.
The summary isn’t nearly as detailed as the “green room installation” so
it might be a good idea to use them concomitantly… so here goes.\
Installation
Installing XCode
As of XCode 4.3.2 they no longer provide command line utilities along
with XCode download package. Therefore, after downloading XCode from the
App Store, go to: XCode > Preferences > Downloads
and ensure that you
download the command line utilities.\
To ensure that the command line utilities have been downloaded and are
functioning properly, type the following commands into Terminal:
$ gcc
You should see something returned something along the lines of
$ i686-apple-darwin11-llvm-gcc-4.2: no input files
This indicates that you do in fact have the command line utilities (this
specific return indicates that there is a Gnu C Compiler Present).
However, if you get something along the lines of
$ -bash: gcc: command not found
You do not have the appropriate command line utilities from XCode
and should re-attempt teh download (or Google it and figure out what
went wrong).
Given that you have a gcc, then you can procede to the next sections.
Installing Homebrew
The most current way to install Homewbrew can be found
here, however,
currently the command below functions properly.
NOTE: The command below assumes that you do not have .git
installed
/usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
Now to install any other components that Brew needs to function
propertly, type:
$ brew update
The final line of the terminal output should be:
Already up-to-date.
Next (also to ensure that things are completely installed), type in the
following:
$ brew doctor
If everything is fine and ready to go with Homewbrew, you will get the
message:
Your system is raring to brew.
However, i when I type it in, I get the following Message (and this is
different than the “green room” tutorial, probably because of XCode’s
recent change in the install methodology that I mentioned):
Warning: Your Xcode is configured with an invalid path.
You should change it to the correct path. Please note that there is no correct path at this time if you have *only* installed the Command Line Tools for Xcode.
If your Xcode is pre-4.3 or you installed the whole of Xcode 4.3 then one of these is (probably) what you want:
sudo xcode-select -switch /Developer
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Homebrew is generally pretty good about telling you what you need to do
(although it’s always a good idea to look up what the terminal command
is going to
do),
so I followed the 2nd brew command, and typed:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Then, to see if we’re ready to go now, I again typed:
$ brew doctor
and now I get the message:
Your system is raring to brew.
One down…
Installing Python, Pip, Numpy, SciPy, Pandas & iPython
If you’re not aware of what what your ~/.bash_profile
is, take a
peek because you need to
add the following two lines to it (if they’re already there, then skip
this step):
export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/share/python:$PATH
In the “green room” tutorial, this is done in a piecemeal fashion (and I
thought I had made a mistake in my install by doing it out of order) so
I did it outright at the beginning at it didn’t seem to cause any
problems.
Close out of your current terminal, open a new one, and give it a
$ echo $PATH
and make sure you see the two file paths referenced
above. If so, let’s keep moving.
Install Python
$ brew install readline sqlite gdbm pkg-config
$ brew install python --framework --universal
To finish the Python installation (and make an alias to where the newest
Python version should point), type in the following:
NOTE: If your Python version is not 2.7.3, then you would need to
<TAB>
into the appropriate folder on the 3rd line (where I have
/../Cellar/python/2.7.3/
). Don’t just mindlessly copy and paste,
you’re in the Terminal
for God’s Sake!
$ cd /System/Library/Frameworks/Python.framework/Versions
$ sudo rm Current
$ sudo ln -s /usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/Current
Pip, SciPy, Numpy, & Matplotlib
Now install pip,
by using:
$ easy_install pip
To test the installation of pip type:
$ which pip
and you should see the following returned:
/usr/local/share/python/pip
Next use pip to install virtualenv
and virtualenvwrapper
:
$ pip install virtualenv
$ pip install virtualenvwrapper
$ source /usr/local/share/python/virtualenvwrapper.sh
Install Numpy via:
$ pip install numpy
Install SciPy also using pip – the “green room”
link installs SciPy using the github.egg
however, they’ve fixed things
now so you can use the method below. The first command gets the required
Fortran compiler:
$ brew install gfortran
$ pip install scipy
Pip Install Matplotlib
$ pip install -e git+https://github.com/matplotlib/matplotlib#egg=matplotlib-dev
iPython, Pandas, SciKits, & Nose
Pip Install iPython
$ pip install ipython
then:
$ brew install pyqt
append your ~/.bash_profile
with the appropriate statement given to
you at the END of the pyqt installation, for me it was:
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
Then:
$ brew install zmq
$ pip install pyzmq
$ pip install pygments
Install Pandas:
$ pip install pandas
Install Scikits.Statsmodels
$ pip install scikits.statsmodels
Lastly, to ensure that we have the necessary testing suites to check the
packages that we’ve just installed. The testing suite that
(conveniently) all of these packages is called nose
.
$ pip install nose
And we are finished with the installation!
Installation Testing
Numpy Testing
First, let’s check the installations of Numpy and SciPy, as is provided
on their
documentation\
In terminal, here is what to type, along with the output that I get
back:
$ python
Python 2.7.3 (default, Apr 20 2012, 17:20:12)
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.test('full')
...
[lots of text]
...
[final lines]
----------------------------------------
Ran 3552 tests in 35.886s
FAILED (KNOWNFAIL=3, SKIP=1, failures=9)
Although it’s not perfect with 0 failures, I’ll definitely take it. One
issue of many that prompted me to reinstall Python and these libraries
is that when I would run this test, my Terminal would crash and quit
(for both Numpy
and Scipy
)… yeah, not good.
SciPy Testing
Now let’s test SciPy.
>>> import scipy
>>> scipy.test()
...
[lots of text]
...
[final lines]
-----------------------------------------
Ran 5101 tests in 56.231s
FAILED (KNOWNFAIL=12, SKIP=42, failures=9)
Again, not batting 1000, but I’m definitely satisfied.
Pandas Testing
And lastly, let’s make sure that Pandas
is working properly.\
>>> exit()
$ nosetests pandas
...
[lots of periods, S's and other things]
...
Ran 1509 tests in 70.357s
OK (SKIP=11)
So at this point, I’m raring to go with Python and some pretty heavy
duty scientific computing capabilities!