Fwd: [Matplotlib-users] Installing NumPy / SciPy / Matplotlib / IPython on Mac OS 10.7 (Lion)

62 views
Skip to first unread message

Keith Hughitt

unread,
Mar 6, 2012, 3:54:07 PM3/6/12
to su...@googlegroups.com
Another possible route for Mac installation.

---------- Forwarded message ----------
From: Ludwig Schwardt <ludwig....@gmail.com>
Date: Tue, Feb 21, 2012 at 7:17 AM
Subject: [Matplotlib-users] Installing NumPy / SciPy / Matplotlib / IPython on Mac OS 10.7 (Lion)
To: matplotl...@lists.sourceforge.net
Cc: Nicolas Le Bihan <Nicolas....@gipsa-lab.grenoble-inp.fr>


Hi all,

This is a topic that I have spent way too many hours on... Ever since
Mac OS 10.4 I have been fine-tuning installation instructions for
these packages, aiming for the shortest instructions installing as few
extras as possible. With Lion it is finally getting very simple :-)

First off, I agree that the Enthought Python distribution is a good
way to go. It has the downsides of being a separate Python
installation (at least pretty well implemented) and costing quite a
bit of money to get the full functionality. So if you want an
alternative costing only a little bit of effort, read on...

Second, I would not recommend installing another Python on a Mac
unless you know what you are doing. Just use the system-provided
Python! In my experience the Mac environment is not very well
configured to handle multiple Pythons and you can easily find your
Python code using some bits of the one Python distribution and some of
the other, leading to strange bugs. Ask yourself whether you really
need Python 2.7.2 when you already have 2.7.1 installed. [Yes, I know
you can "brew install python", but it goes against the whole
philosophy of Homebrew, doesn't it?]

This installs the latest stable releases of these packages, using only
Homebrew and easy_install. I use the system-provided NumPy 1.5.1, as
this is good enough for most purposes and therefore one less package
to install. I assume that you have Lion, Xcode 4 and not much else
(see the more detailed instructions below if you have more than this).

For the impatient, here are my instructions ready to be entered on
your Terminal:


/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
brew update
brew install pkg-config gfortran zeromq pyqt
echo "export PYTHONPATH=/usr/local/lib/python:\$PYTHONPATH" >> ~/.bash_profile
sudo easy_install nose Sphinx readline Pygments pyzmq IPython matplotlib
sudo CC=clang CXX=clang++ FFLAGS=-ff2c easy_install scipy


I also attach a more detailed description below, including tests to
check whether your installation works. Now to put all of this on a
blog... :-)

Enjoy and good luck,
Ludwig



Installing NumPy / SciPy / Matplotlib / IPython on Mac OS 10.7 (Lion)
=====================================================================

Updated 21/02/2012

Apple Software
--------------

- Install Mac OS 10.7 (Lion) from the App Store

- Do a Software Update

- Install Xcode 4 from the App Store. You need to run the "Install Xcode" app
 that is downloaded to /Applications. Test Xcode by confirming that "gcc" runs
 in the Terminal.

Homebrew
--------

- In preparation for homebrew, the best option is to delete /usr/local via::

 sudo rm -rf /usr/local

 and install any software in it via homebrew instead. If this step fills you
 with dread and you do not want to lose your beloved third-party software, the
 second-best option is to make sure you have write permission for the directory
 via::

 sudo chown -R username:staff /usr/local

- Install Homebrew (http://mxcl.github.com/homebrew/) by running the following
 command in the Terminal::

 /usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"

- Run "brew update" to get the latest formulas

- Install the first package, just to have an existing homebrew Cellar::

 brew install pkg-config

- Run "brew doctor" and check the suggestions. Specifically, comment out
 references to Mac OS 10.6 in ~/.profile, contained in environment variables
 such as MACOSX_DEPLOYMENT_TARGET, CFLAGS, LDFLAGS and FFLAGS.

- Now install the following packages::

 brew install gfortran zeromq pyqt

- Add the following lines to your ~/.bash_profile (or ~/.profile if it exists)::

 # This is for SIP (and PyQT) as installed (and suggested) by Homebrew
 export PYTHONPATH=/usr/local/lib/python:$PYTHONPATH

IPython
-------

- Install the following Python packages (nose is for running unit tests, Sphinx
 creates documentation and readline, Pygments and pyzmq enhance IPython)::

 sudo easy_install nose Sphinx readline Pygments pyzmq IPython

NumPy
-----

- Lion comes with NumPy 1.5.1 out of the box. This is sufficient for our
 purposes, and we therefore use the system version. We can verify it by running
 the test suite from within Python::

 import numpy as np
 np.test('full')

 The result for NumPy version 1.5.1 is (the failures may be ignored)::

 FAILED (KNOWNFAIL=4, SKIP=1, failures=8)
 <nose.result.TextTestResult run=3019 errors=0 failures=8>

SciPy
-----

- The current stable version of SciPy compiles on Lion, as long as you pass the
 appropriate compiler flags (you need at least 0.10.0)::

 sudo CC=clang CXX=clang++ FFLAGS=-ff2c easy_install scipy

- Test that the installation worked by running the test suite from within
 Python (first change to another directory before running Python)::

 import scipy
 scipy.test()

 The result for SciPy version 0.10.0 is (the failures may be ignored)::

 FAILED (KNOWNFAIL=12, SKIP=36, failures=8)
 <nose.result.TextTestResult run=5095 errors=0 failures=8>

Matplotlib
----------

- If you want support for TeX rendering in matplotlib, install MacTeX first from
 http://www.tug.org/mactex.

- Matplotlib is now easy_installable on Lion (you need at least version 1.1.0)::

 sudo easy_install matplotlib

- Test that the installation worked by running the test suite from within
 Python (first change to another directory before running Python)::

 import pylab
 pylab.test()

 The result for Matplotlib version 1.1.0 is::

 OK (SKIP=1)
 <nose.result.TextTestResult run=156 errors=0 failures=0>

- A more thorough test of Matplotlib involves the following::

 brew install libjpeg
 wget http://effbot.org/downloads/Imaging-1.1.7.tar.gz
 tar xzvf Imaging-1.1.7.tar.gz
 cd Imaging-1.1.7
 <... edit setup.py so that 'FREETYPE_ROOT = libinclude("/usr/X11R6")' ...>
 python setup.py build
 sudo python setup.py install
 <... start python ...>
 import matplotlib
 matplotlib.test()

 The result for Matplotlib version 1.1.0 is (this takes a while!)::

 Ran 993 tests in 208.338s
 OK (KNOWNFAIL=264)

 This generates a lot of test images in the current directory - feel free to
 wipe the result_images/ directory afterwards.

- Install the matplotlibrc file in your home directory and edit it to select the
 default backend. If you followed these instructions you should be able to use
 the MacOSX, TkAgg and Qt4Agg interactive backends::

 mkdir ~/.matplotlib
 cp /Library/Python/2.7/site-packages/matplotlib-1.1.0-py2.7-macosx-10.7-intel.egg/matplotlib/mpl-data/matplotlibrc
~/.matplotlib
 vi ~/.matplotlib/matplotlibrc

- For fun, try out the new IPython Qt console and HTML notebook with inline
 Matplotlib plots (assuming you have at least IPython version 0.12). This is a
 good test to verify that all the previous steps worked. In the Qt console,
 type `plot([1,2])` to see an inline plot appear (this also highlights the
 function help docstring that pops up as you type). In the notebook, click on
 "New Notebook" on the initial HTML page that pops up in your browser, and type
 `plot([1,2])` in the first cell of the notebook page, followed by Shift-Enter
 to see the inline plot::

 ipython qtconsole --pylab=inline
 ipython notebook --pylab=inline

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Matplotlib-users mailing list
Matplotl...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

DVD PS

unread,
Mar 7, 2012, 5:15:40 AM3/7/12
to su...@googlegroups.com
I'm feeling great today!! I'm realizing more and more that there's more people out there going in the same direction I'm going ;-)

One important thing I found nice using the approach I did (virtual_env + homebrew + python official installation) is that we can package the whole thing for different architectures and the people has just to untar it and use it.  I know it is not ideal, but it would save us of a lot of hazard and complains... So I propose to have two options, one for the user (download and use) and another for the hard-core guys, install, compile and fight.  I will try some time this week to package my installation and deployed it in a similar mac to see how it works.  I will update the mail list.

Cheers,
David

Keith Hughitt

unread,
Mar 7, 2012, 6:46:54 AM3/7/12
to su...@googlegroups.com
I think a lot of people who really like that. Out of curiosity, how well do easy_install / pip work on OS X? If they worked for most things then you could also just have users do something like:

sudo pip install numpy scipy matplotlib pyfits suds pil

pip is similar to easy_install but has better support for things like uninstalling and upgrading python packages.

One problem though is that easy_install/pip might need to compile some things, so if you don't have the necessary libraries installed (e.g. python-dev on most linux distributions) it will fail.

Keith

--
You received this message because you are subscribed to the Google Groups "SunPy" group.
To post to this group, send email to su...@googlegroups.com.
To unsubscribe from this group, send email to sunpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sunpy?hl=en.

DVD PS

unread,
Mar 7, 2012, 7:07:18 AM3/7/12
to su...@googlegroups.com
Hi Keith,

I've just tried this on the other 'virgin' mac


and, now that I remember,  I found the problem  I got into last time... I couldn't install pip.  That's why I change strategy to virtual_env which come with pip installed.

sudo pip install numpy scipy matplotlib pyfits suds pil

Also, for numpy you need gfortran, and pkgconfig...

Cheers,
David

Keith Hughitt

unread,
Mar 7, 2012, 9:43:57 AM3/7/12
to su...@googlegroups.com
Hi David,

What happens when you tried to install pip? Another person suggests using easy_install to install pip. Do you have easy_install on the virgin mac installation?

Are there any easy ways to install gfortran and pkgconfig on Mac?

On Debian/Ubuntu there is convenient command to install all of the libraries needed to build something from source (apt-get build-dep), e.g.:

sudo apt-get build-dep python-numpy python-scipy matplotlib
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  dvipng graphviz libamd2.2.0 libbtf1.1.0 libcamd2.2.0 libccolamd2.7.1 libcholmod1.7.1 libcsparse2.2.3
  libcxsparse2.2.3 libffi-dev libklu1.1.0 libldl2.0.1 libqt4-designer libqt4-help libqt4-scripttools
  libqt4-test libqtassistantclient4 libqtwebkit4 libsuitesparse-dev libumfpack5.4.0 libwxbase2.8-dbg
  libwxgtk2.8-dbg libxss-dev python-antlr python-epydoc python-gobject-2-dev python-gobject-dev
  python-gtk2-dev python-numpy-dbg python-qt-dev python-qt4 python-qt4-dev python-setuptools
  python-sip python-sip-dev python-traits python-wxgtk2.8-dbg python-xlwt sharutils swig tcl8.5-dev
  tk8.5-dev wx2.8-headers x11proto-scrnsaver-dev

There is also a meta-package called "build-essential" which installs a bunch of useful compilers, including gfortran.

If only there were something similar on Macs :\

Keith

DVD PS

unread,
Mar 7, 2012, 10:23:27 AM3/7/12
to su...@googlegroups.com
On 7 March 2012 14:43, Keith Hughitt <keith....@gmail.com> wrote:
Hi David,

What happens when you tried to install pip? Another person suggests using easy_install to install pip. Do you have easy_install on the virgin mac installation?

It didn't work as it, but I downloaded the package from the browser and then install it (I suppose it has to do with the proxy in here).   After install it, I try to run pip install numpy, and I got to the fortran problem...
 
 
Are there any easy ways to install gfortran and pkgconfig on Mac?

That's one of the advantages of homebrew.  I will clean all this computer and try it from scratch, as I did with mine, because it seems that it has a older version of Xcode non compatible with the actual system...  I thought it was completely clean :-S
 

On Debian/Ubuntu there is convenient command to install all of the libraries needed to build something from source (apt-get build-dep), e.g.:

sudo apt-get build-dep python-numpy python-scipy matplotlib

Ohhh yes,  what are you going to tell me....



If only there were something similar on Macs :\

I'm not completely sure... but it seems that homebrew solve that (and some how better than ports and fink...) or that's my understanding...

David
Reply all
Reply to author
Forward
0 new messages