Python on OS X 10.9 Mavericks

Written by . Filed under Mac, Programming, Python. Bookmark the Permalink. Post a Comment. Leave a Trackback URL.

I upgraded my older MacBook Pro to a new retina MacBook Pro.
For a couple of generations I used to migrate everything over to a new machine with the migration assistant or in target mode.

This time I used the chance to start over new since the system was clogged with a number of environments that became problematic (Ruby and Python installs, which weren’t always easy under rechten Mac OS versions).

Also wanted to replace legacy Macports installs with homebrew.

Pawel Lachowicz shares his how-to for installing Python on Mavericks:
www.quantatrisk.com
In this how-to I will generally follow Pawel’s list of packages to install. But doing so I will note errors, mitigations and changes I encountered during install.

I also installed R which for some functions relies on TCL/TK. Which is outdated on Mavericks, do R brings it’s own TCL/TK install package.
Since is installs to /usr/local it can potentially interfere with homebrew (according to brew doctor).

So I would rather recommend to remove the TCL/TK install that comes with package R and use the homebrew TCL/TK libs.
So far I have not tried homebrew R.

To be able to uninstall and to install different versions of Python I followed this recommendation on hackercodex.com.

First, install homebrew:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

brew install python --with-brewed-openssl
brew install python3 --with-brewed-openssl

virtualenv allows to install Python packages into different virtual environment. In turn this allows i.e. testing different versions of packages or different package sets.
Python packages can be installed with the older setuptools or the newer pip.
See here at hackercodex.com for advantages/disadvantages.
pip allows uninstall, so I chose pip.

pip install virtualenv

To make proper use of virtualenv one needs to create and activate an environmen, i.e.:
mkdir ~/source/virtualenvs
cd ~/source/virtualenvs
virtualenv quant
cd quant
. bin/activate

A virtualenv can be deactivated like this:
cd ~/source/virtualenvs/quant
. bin/deactivate

Then, go on installing the packages recommended by Pawel:

  • pip install mpmath
  • pip install numpy

The next package, scipy requires a Fortran compiler.
I did not have one installed. On my fresh OS X Mavericks install homebrew was the easiest solution. But is also possible to install Fortran from the Mac OS X 10.7 (Lion) installer, see Jonathan Goldsmith’s post at github.

brew install gfortran

Then continue:

  • pip install scipy
  • brew install pkg-config
  • brew install freetype
  • brew install libpng
  • brew install ffmpeg
  • pip install matplotlib

Trying to install matplotlib yields another error:

With the version change from matplotlib 2.5.0.1 to 2.5.1 the header directory structure was changed (see here). This is known, but seems to not have been fixed yet in the pip package.

This solution from David at stackoverflow solved the problem:

sudo ln -s /usr/X11/include/freetype2/freetype /usr/X11/include/

Again, continue installing packages:

  • brew install zeromq
  • pip install pyzmq
  • Already installed in site-packages with homebrew python 2.7.6: pip install Tornado
  • pip install readline
  • pip install azure
  • Skipped: pip install curses
  • pip install cython
  • pip install jinja2
  • pip install pexpect
  • pip install pygments
  • pip install pymongo
  • pip install sphinx
  • Skipped, since already installed by brew via dependency: pip install sqlite3
  • pip install wx
  • Skipped, since already installed by brew via dependency: pip install zmq
  • pip install sympy
  • pip install patsy
  • pip install scikit_learn
  • Note: statsmodels requires pandas, so install pandas first.
    pip install pandas
  • pip install statsmodels
  • pip install ipython
Be Sociable, Share!
  • Twitter
  • Facebook
  • email
  • StumbleUpon
  • Delicious
  • Google Reader
  • LinkedIn
  • BlinkList

2 Comments

  1. sungkwon.eom
    Posted March 4, 2014 at 10:00 | Permalink

    Thanks for your great articel…

    After installing pyzmq, I got an error as below….
    Any help?
    =======================================
    File “/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/gevent_zeromq/core.py”, line 36, in __init__
    self.__in_send_multipart = False
    File “/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/zmq/sugar/attrsettr.py”, line 38, in __setattr__
    self.__class__.__name__, upper_key)
    AttributeError: GreenSocket has no such option: _GREENSOCKET__IN_SEND_MULTIPART
    failed with AttributeError

    • Posted March 4, 2014 at 10:42 | Permalink

      Strange, I did not get this error .
      google shows there were some changes to zeromq / pyzmq:
      https://github.com/locustio/locust/issues/58

      You could try to update your zeromq or uninstall and then reinstall pyzmq and zeromq, (Update your homebrew before reinstall)

One Trackback

Post a Comment

Your email is never published nor shared.

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>