[edit: It looks like things have changed a bit since the release of 10.7, so your mileage may vary with this method. This was written when 10.7 was brand new and most software was not yet updated for it.]
For those of you that do not know, Matplotlib is an excellent Python plotting library that allows you to create professional-quality plots for inclusion on web pages, Latex documents, Beamer presentations, Keynote presentations, and any other software that can import SVG, EPS, PNG, or virtually any graphic format.
However, getting matplotlib installed on Mac OS X 10.7 can be a bit tricky, especially if you are using Homebrew as your “package manager.” First off, Homebrew does not have packages for matplotlib, as well as some of its dependencies. Additionally, the current Matplotlib release version (1.0.1 as of this post) does not compile out-of-the-box against libpng 1.5, which is included in the X11 distribution shipped with Mac OS X 10.7.
For previous versions of Mac OS X (10.6, 10.5), the usual way to install matplotlib was to install python, pkg-config, and gfortran with Homebrew, then install numpy and matplotlib through pip, ala:
|
1 2 3 4 5 6 |
$ brew install python
$ brew install gfortran
$ brew install pkg-config
$ easy_install pip
$ pip install numpy
$ pip install matplotlib |
Unfortunately, as previously mentioned, all is not so easy in the world of Mac OS X 10.7, and the difficulty lies with libpng 1.5, installed with Mac OS X 10.7′s version of X11. Briefly put, Matplotlib 1.0.1 is not compatible with libpng 1.5 due to a change in the API. Fortunately, the fix is already applied up-stream and will probably be a part of Matplotlib 1.0.2, or 1.1.0, or whatever the next released version is.
Until the next release, the Matplotlib sources in Git can be used. Instead of pulling the sources from the Matplotlib SourceForge site, you need to pull them from the Matplotlib GitHub site. I’m not sure if this GitHub site is “official,” but is looks to be.
All that is needed is to build Matplotlib from source instead of using pip, so the installation procedure is now:
|
1 2 3 4 5 6 7 8 9 10 |
$ brew install python
$ brew install gfortran
$ brew install pkg-config
$ easy_install pip
$ pip install numpy
$ cd $HOME
$ git clone https://github.com/matplotlib/matplotlib.git
$ cd matplotlib
$ python setup.py build
$ python setup.py install |
And now you’re good to go! Hopefully this will become much easier with the next official release of Matplotlib.
Thanks! This solved my problem.
Thanks for this.
Great… This worked for me… Excellent!!!!
Although I am on OSX10.6.8, and recently installed python2.7 using Homebrew. But it was BIG problem in installing matplotlib using- $pip install matplotlib (even with option -f ). But this set of instructions worked well! I also tested it, hopefully its fine.
But I still have a question- the make.osx file still has PYVERSION=2.6 (?)
I doubt that really matters. I haven’t had any problems with it yet.
Worked for me but why gfortran?
gfortran is a dependency of some parts of numpy. It may be possible to disable the Fortran bindings during the numpy build, but I have not looked too deeply into it.
AFAIK, this is simply not true. Numpy _can_ be built against BLAS/LAPACK, for which you need a fortran compiler (e.g. gfortran). However, OS X ships with both a BLAS and a LAPACK implementation pre-compiled, so there is no need to supply these on your own. Also, if no BLAS/LAPACK or fortran compiler is available, you can still build numpy with its own “lapack lite”, which only requires a C compiler.
Pingback:How To Install Python’s Matplotlib on Mac OS X Lion ⊆ David Xia
I followed your instructions and all went OK, except that once I want to use it I fail the following (1),
[checking the web some other people hat also problems with this but they had the libfreefonts.... included in the ft2font.so (see further below [2])
Given the error it misses some font stuff [this is macosx 10.7 and an matplotlib 0.99 works,
but I need a command from the newer distribution.
Any idea how to approach this [using brew]
(1)
ImportError: dlopen(/Users/beerli/src/matplotlib/lib/matplotlib/ft2font.so, 2): Symbol not found: _FT_Attach_File
Referenced from: /Users/beerli/src/matplotlib/lib/matplotlib/ft2font.so
Expected in: dynamic lookup
(2)
ciguri:histograms>otool -L /Users/beerli/src/matplotlib/lib/matplotlib/ft2font.so
/Users/beerli/src/matplotlib/lib/matplotlib/ft2font.so:
/usr/local/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 53.0.0)
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 41.0.0)
/usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1105.0.0)
How exactly are you installed matplotlib? Are you installing against the system python 2.6, or the brew python 2.7? In my installation, the ft2font.so file resides in /usr/local/lib/python2.7/site-packages/matploblib. It also has /usr/X11/lib/libfreetype.6.dylib as a dependency, which is what contains the missing symbol. Try installing matplotlib and see if that helps to resolve this link error.
Justin,
thanks, you are correct!
I read some more after I posted my message, and found another thread that suggest that one needs
export CFLAGS=”-I/usr/X11/include -I/usr/X11/include/freetype2 -I/usr/X11/include/libpng12″
export LDFLAGS=”-L/usr/X11/lib”
and after that I was able to
run the the setup.py without a problem
thanks again for running this site
Peter
Thanks a lot. I was having a compilation problem on Fedora – probably a python 2.7 bug as mentioned at
http://stackoverflow.com/questions/6936884/how-to-install-matplotlib-on-mac-10-7-in-virtualenv
Pulling from git solved it for me.
Thanks for the help, it works
With
pipyou can directly install from a git repo:pip install -e git://github.com/matplotlib/matplotlib.git@v1.1.0-rc1#egg=matplotlib
See pip documentation for details at http://www.pip-installer.org
I have tried every single combination of instructions I’ve seen anywhere to install matplotlib on 10.6.8 on my MBP. I’ve gotten it to install on my iMac at work using the instructions above but when I go to actually load matplotlib, I get the following error:
Traceback (most recent call last):
File “plot.py”, line 1, in
import matplotlib.pylab as plt
File “/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.4-x86_64.egg/matplotlib/pylab.py”, line 221, in
from matplotlib import mpl # pulls in most modules
File “/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.4-x86_64.egg/matplotlib/mpl.py”, line 2, in
from matplotlib import axis
File “/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.4-x86_64.egg/matplotlib/axis.py”, line 10, in
import matplotlib.font_manager as font_manager
File “/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.4-x86_64.egg/matplotlib/font_manager.py”, line 1323, in
_rebuild()
File “/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.4-x86_64.egg/matplotlib/font_manager.py”, line 1273, in _rebuild
fontManager = FontManager()
File “/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.4-x86_64.egg/matplotlib/font_manager.py”, line 997, in __init__
self.afmlist = createFontList(self.afmfiles, fontext=’afm’)
File “/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.4-x86_64.egg/matplotlib/font_manager.py”, line 565, in createFontList
prop = afmFontProperty(fpath, font)
File “/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.4-x86_64.egg/matplotlib/font_manager.py”, line 501, in afmFontProperty
weight = weight_as_number(font.get_weight().lower())
File “/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.4-x86_64.egg/matplotlib/afm.py”, line 464, in get_weight
return self._header['Weight']
KeyError: ‘Weight’
Does anyone have any ideas?
Turns out this was neither a problem with python or matplotlib. As someone suggested on the matplotlib users mailing list, the problem in afm.py pointed to bad *.afm files. After inserting a print statement before 565 in afm.py, I was able to identify and isolate 5 font families that were causing the problem.
In addition to the suggested procedure in the post, I additionally had to install dateutil with:
pip install python-dateutil==1.5
I feel quite embarrassed that I’ve gone through 2 days of trying to get to get this to work. I’ve scraped through github forums, stackoverflow and all the links that can bide me some type of logic. Yet, alas I still fail wildly with this set of errors:
In file included from src/backend_agg.cpp:11:
In file included from src/_backend_agg.h:34:
agg24/include/agg_renderer_outline_aa.h:1368:45: error: binding of reference to type ‘agg::line_profile_aa’ to a value of type ‘const agg::line_profile_aa’ drops qualifiers
line_profile_aa& profile() { return *m_profile; }
^~~~~~~~~~
1 error generated.
error: command ‘/usr/bin/clang’ failed with exit status 1
—————————————-
Command /Users/Will/.virtualenvs/test1/bin/python -c “import setuptools; __file__=’/Users/Will/.virtualenvs/test1/src/matplotlib/setup.py’; exec(compile(open(__file__).read().replace(‘rn’, ‘n’), __file__, ‘exec’))” develop –no-deps failed with error code 1 in /Users/Will/.virtualenvs/test1/src/matplotlib
Storing complete log in /Users/Will/.pip/pip.log
I am stuck at the same point as William Jennings. Any suggestions?
Unfortunately, no. The only suggestion I can make would be to try a different Matplotlib revision. Does the 1.0.1 release for you? That is the version against which the post was written.
Thanks a lot! This finally worked
Thank you so much!! Now working for me on Mac Lion……Really appreciated and really nice explained….THANKS A LOT!!!
Amazing!! After about 2.5h this finally worked for me. Thanks!
thanks v much. v useful
Thanks again for the guide.. i’m almost done.
I needed to use
sudo /usr/local/bin/python /usr/local/bin/pip install numpy
instead of
pip install numpy
but it worked!
The first thing you need to do before anything else is to get yourself a domain name. A domain name is the name you want to give to your website. For example, the domain name of the website you’re reading is “thesitewizard.com”. To get a domain name, you have to pay an annual fee to a registrar for the right to use that name. Getting a name does not get you a website or anything like that. It’s just a name. It’s sort of like registering a business name in the brick-and-mortar world; having that business name does not mean that you also have the shop premises to go with the name.;
Our favorite internet page
<"'http://www.caramoantourpackage.com/caramoan-tour-package/
building websites is easy if you have access to HTML WYSIWIG editors.”
Most up-to-date write-up straight from our personal web page
<="http://www.caramoan.ph/caramoan-tour/