[Pythonmac-SIG] Re: matplotlib on Tiger?

I believe I said I would make a pkg for OS 10.4, not python 2.4.1.
Sorry if I said the later. I am waiting a little while now, since it
seems 0.81 is having tex issues and there may be a version bump here soon.
  I could help you through the install you mentioned. Installing each
dependency would probably be just as easy as trying to use components
customized install from the tiger installer to install just freetype and
libpng. You have to make a few small edits to setup.py to make it work
with those.

- Charlie

···

from my installer. There is nothing stopping you from choosing a

fghorow.11707581@...643... wrote:

Thanks to everybody for the informative replies!

I'm now trying to decide
my best course of action. The way I see the current situation, there is Charlie's
standalone installer from IU, but that does not integrate with the pythonmac.org
installation (which currently affects me greatly, because I'm running Tiger
and the pythonmac.org 2.4.1 "framework"). Then there is the pythonmac installer,
which puts stuff into the Apple installation of 2.3....

I've tried a few
obvious things (like soft-linking the pythonmac 2.3 matplotlib directory under
its site-packages to the 2.4.1 pythonmac.org's site-packages), but nothing
has worked yet.

IIRC, Charlie(?) said in an earlier post that he was going
to build against 2.4.1 and post the results (to the IU website?) once he got
home to a machine with 2.4.1 on it. It seems to me that this should solve
my problem, but I might be missing something, and hence need to compile from
source. Not a big deal at all for the python stuff (hooray for setup.py! :wink:
but I would then need to fight 'dependency hell' for all of the missing libraries
from my installations. I was kind of hoping to find that someone else had
already won that battle! :wink:

Should it come down to that, I'd be happy
to post any sucess stories from my ham-fisted attempts to build the .dmg anywhere
that it useful to the wider community.

To recap: for pythonmac.org 2.4.1
users there does not seem to exist a usable installer for matplotlib.

--- Charles Moad <cmoad@...139... wrote:

   All the binaries I provide

depend on the system installed python

(i.e. python2.3.x). These binaries

are meant for people who want a

one click installer for matplotlib in

OSX that includes all needed

dependencies. I would expect more seasoned

python users to install

the packages from pythonmac.org. I will add

a note on the site.

    For the record, if anyone wants the Xcode project

files for the

freetype and libpng frameworks I provide, just ask.

- Charlie

On Jun 7, 2005, at 4:28 PM, Chris Barker wrote:

Charles Moad wrote:

   I am posting a new 0.81 build

with basemap-0.5 right now for

Panther.

But does this

use python 2.4 ? That wasn't' clear to me from the

download page.

- Chris
--
Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point

Way NE (206) 526-6329 fax

Seattle, WA 98115 (206) 526-6317

  main reception

Chris.Barker@...259...

-------------------------------------------------------

This SF.Net email is sponsored by: NEC IT Guy Games. How far can
you shotput
a projector? How fast can you ride your desk chair down

the office

luge track?
If you want to score the big prize, get

to know the little guy.

Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20

_______________________________________________
Matplotlib-users

mailing list

Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

_______________________________________________
Pythonmac-SIG

maillist - Pythonmac-SIG@...48...

http://mail.python.org/mailman/listinfo/pythonmac-sig

Charles Moad wrote:

Installing each
dependency would probably be just as easy as trying to use components
from my installer.

I put instructions for how to do this in my package for OS-X-10.3, py2.3.0. Here they are. If you do all this, you can donate the package to Bob's repository on pythonmac.org.

There is a related thread about defining a standard way to do this for matplotlib, so it will build out of the box.

They should work just fine for newer versions of OS, matplotlib, and python. Sorry they are a bit wordy:

Installing matplotlib on OS-X (10.3.7)

Here are my notes as to what it took to get matplotlib (0.71) installed and working on OS-X. I have so far kept a fink-free system, so that's what I've done here as well. I use it with the AGG back end for generating images for a web site, and hopefully with the wx backend for interactive use and embedding in wx Applications. I've also quickly got it working with TK. Note that this is kind of a running commentary, not well edited. I'd read the whole thing before starting.

1) Requirements:

···

-------------------------------------------
According to the matplotlib install docs (http://matplotlib.sourceforge.net/installing.html), you need the following:

freetype (>= 2.1.7)
libpng
zlib

Personally, I've been avoiding Fink, as it doesn't seem to play well with the rest of OS-X, including the Apple supplied Python, so I've looked elsewhere for these libs.

a) Freetype:
I seem to have it in:

/usr/X11R6/include/freetype2

I don't think I installed it myself, so it probably came with Apple's X11, Which I did install.

However, I seemed to be having problems with that version, so I looked, and it seems to be:

libfreetype.6.3.dylib

Given that freetype2 is currently at version 2.1.9, I have no idea what to make of that! So off to sourceforge to get a new freetype:

http://freetype.sourceforge.net/index2.html

where I got:

freetype-2.1.9.tar.gz

Following the instructions in docs/INSTALL.UNX:

$ ./configure
$ make
$ sudo make install

That puts it in /usr/local/..., which is a good place for it.

NOTE: The above will build freetype as a shared library, which is fine if you are building ot run on the same system you are building on. However, if you want to buuild a re-distributable package, you'll need a static library, which you can get by doing:

$ ./configure --disable-shared --enable static
$ make
$ sudo make install

Hmm. that made the static libs (*.a) , but also the dynamic ones.

Make sure to do:
$ make clean

if you had already built it. You may also have to remove the shared libs, so that they won't be found (*.dyld). I had to remove them from /usr/local/lib.

b) zlib:
I have:
/usr/include/zlib.h

I don't know where I might have gotten it, but there it is.

NOTE: I checked on another system in my office, and it doesn't have zlib. It does, however have libz, which I am told is the same thing, to you shouldn't need this.

c) libpng:
This, I didn't have on my system, except inside the wxWidgets source tree, so I went looking for it.

Note that you need zlib to compile libpng, so make sure you have that first.

I did a google search for "libpng OS-X". I found:

http://www.libpng.org/pub/png/pngcode.html

Which led me to the libpng sourceforge site.

From there I downloaded:

libpng-1.2.8.tar.gz

unpacked it, and opened a terminal in the libpng-1.2.8 directory, and did:

$ cp scripts/makefile.darwin ./makefile

(note that according to the INSTALL, there is supposed to be a makefile.macosx, but it wasn't there)

I took a look in the makefile, and found:

ZLIBLIB=/usr/local/lib
ZLIBINC=/usr/local/include

Which is not where zlib is on my system. However, while I can find zlib.h, I couldn't fine the actual lib, so I tried make without changing anything.

$ make

Which seemed to work fine. zlib must be installed in a standard location, and gcc found it.

$ sudo make install

to install the lib into /usr/local/ (this was specified in the makefile, and it's a good place for it)

$ make test
and
$ ./pngtest pngnow.png

Which both seemed to pass.

If you want to build a re-distributable version of matplotlib, you need the static version of libpng, instead of the dynamic one. It doesn't use ./configure, so instead, I did a:

sudo make install-static

and that installed the *.a files in /usr/local/lib.

d) Numeric or numarray:

I already have Numeric installed, from Bob Ippolito's PIMP (MacPython Package Manager) repostitory. (www.undefined.org/python)

2) Building matplotlib
---------------------------------------------------------
First, I took a look at the matplotlib setup.py. It had "auto" for the back-end flags, so I thought I would give it a try that way:

$python setup.py build

If you have only the static version of libpng and libfreetype (*.a, and not *.dylib) in /usr/local/lib (or anywhere else on your lib search path), then it should link those statically.

That worked!
$ sudo python setup.py install

4) And now to test!

$python

>>> import pylab
Could not open font file /Library/Fonts/NISC18030.ttf
No module named pygtk
PyGTK version 1.99.16 or greater is required to run the GTK Matplotlib backends

This turns out to be because the matlabrc file sets the GTKAgg back end as the default. You have two choices.

1) you can set the back end before importing pylab.
>>> import matplotlib
>>> matplotlib.use('Agg')
>>> import pylab

This works fine

2) Edit the matplotlibrc file. I found it in:
/System/Library/Frameworks/Python.framework/Versions/2.3/share/matplotlib/.matplotlibrc

Change the line:
backend : GTKAgg # the default backend
to
backend : Agg # the default backend

And you're all set to make images for the web, etc.

I'm going to leave getting it to work with wxPython for another day.

3) Building a matplotlib Binary Package for OS-X:

First you need to make sure you've got libpng and libfreetype staticaly linked. I did this by copying the headers and *.a files for them into a directory I created called "StaticLibs", in the main matplot lib directory (the one setup,py is in). You could just as easily put in links, rather than copies, probably a better idea, actually.

Then I edited setupext.py, so that distutils would only look there:

basedir = {
     'win32' : ['win32_static',],
     'linux2' : ['/usr/local', '/usr',],
     'linux' : ['/usr/local', '/usr',],
# 'darwin' : ['/usr/local', '/usr', '/sw', '/usr/X11R6'],
     'darwin' : ['StaticLibs'],
     'freebsd4' : ['/usr/local', '/usr'],
     'sunos5' : [os.getenv('MPLIB_BASE') or '/usr/local',],
}

I'm talking to John Hunter about having a conditional Static setup in the official setup.py to support this. This seemed to so the job.

To test, you can run:

$ otool -L *.so

in the matplotlib directory that is buried in the build directory. it will tell you what libs the matplotlib extensions are linked to. They should not be linked to libfreetype or libpng. libz is OK, it's included with the stock OS-X.

Once you've got that built right, you can make an installer package with Py2App.

This is a note from Bob Ippolito on the macPython mailing list:
"""use bdist_mpkg from py2app to make a redistributable .pkg installer for it. After installing py2app, you should have a tool in /usr/local/bin called "bdist_mpkg" that will Just Do It without any setup.py modifications to the target lib... so go into the matplotlib directory, type bdist_mpkg, and cross your fingers that a dist/matplotlib-xx.pkg
"""
Here's exactly what I tried:

In the matplotlib directory (the same place as setup.py)

$ bdist_mpkg

and it worked!

Note: there are occasionally troubles with installing a newer matplotlib over an older one. You may want to remove an older version before installing, if you have one. To do this, delete:

/Library/Python/2.3/matplotlib/

Then click the mpkg. to install.

Building with tcl/TK:

I downloaded the BI (Batteries Included) installer for tcl/Tk Aqua. It's got a lot of stuff I don't need, but it's only disk space. I then used the MacPython PackageManager and the standard package list, and installed Tkinter from there. It seemed to work.

Now back to the build cycle...Yeah it works!

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Charles Moad wrote:

Installing each
dependency would probably be just as easy as trying to use components
from my installer.

I put instructions for how to do this in my package for OS-X-10.3,
py2.3.0. Here they are. If you do all this, you can donate the package
to Bob's repository on pythonmac.org.

There is a related thread about defining a standard way to do this for
matplotlib, so it will build out of the box.

They should work just fine for newer versions of OS, matplotlib, and
python. Sorry they are a bit wordy:

Installing matplotlib on OS-X (10.3.7)

Here are my notes as to what it took to get matplotlib (0.71) installed
and working on OS-X. I have so far kept a fink-free system, so that's
what I've done here as well. I use it with the AGG back end for
generating images for a web site, and hopefully with the wx backend for
interactive use and embedding in wx Applications. I've also quickly got
it working with TK. Note that this is kind of a running commentary, not
well edited. I'd read the whole thing before starting.

1) Requirements:

···

-------------------------------------------
According to the matplotlib install docs
(http://matplotlib.sourceforge.net/installing.html), you need the following:

freetype (>= 2.1.7)
libpng
zlib

Personally, I've been avoiding Fink, as it doesn't seem to play well
with the rest of OS-X, including the Apple supplied Python, so I've
looked elsewhere for these libs.

a) Freetype:
I seem to have it in:

/usr/X11R6/include/freetype2

I don't think I installed it myself, so it probably came with Apple's
X11, Which I did install.

However, I seemed to be having problems with that version, so I looked,
and it seems to be:

libfreetype.6.3.dylib

Given that freetype2 is currently at version 2.1.9, I have no idea what
to make of that! So off to sourceforge to get a new freetype:

http://freetype.sourceforge.net/index2.html

where I got:

freetype-2.1.9.tar.gz

Following the instructions in docs/INSTALL.UNX:

$ ./configure
$ make
$ sudo make install

That puts it in /usr/local/..., which is a good place for it.

NOTE: The above will build freetype as a shared library, which is fine
if you are building ot run on the same system you are building on.
However, if you want to buuild a re-distributable package, you'll need a
static library, which you can get by doing:

$ ./configure --disable-shared --enable static
$ make
$ sudo make install

Hmm. that made the static libs (*.a) , but also the dynamic ones.

Make sure to do:
$ make clean

if you had already built it. You may also have to remove the shared
libs, so that they won't be found (*.dyld). I had to remove them from
/usr/local/lib.

b) zlib:
I have:
/usr/include/zlib.h

I don't know where I might have gotten it, but there it is.

NOTE: I checked on another system in my office, and it doesn't have
zlib. It does, however have libz, which I am told is the same thing, to
you shouldn't need this.

c) libpng:
This, I didn't have on my system, except inside the wxWidgets source
tree, so I went looking for it.

Note that you need zlib to compile libpng, so make sure you have that first.

I did a google search for "libpng OS-X". I found:

http://www.libpng.org/pub/png/pngcode.html

Which led me to the libpng sourceforge site.

From there I downloaded:

libpng-1.2.8.tar.gz

unpacked it, and opened a terminal in the libpng-1.2.8 directory, and did:

$ cp scripts/makefile.darwin ./makefile

(note that according to the INSTALL, there is supposed to be a
makefile.macosx, but it wasn't there)

I took a look in the makefile, and found:

ZLIBLIB=/usr/local/lib
ZLIBINC=/usr/local/include

Which is not where zlib is on my system. However, while I can find
zlib.h, I couldn't fine the actual lib, so I tried make without changing
anything.

$ make

Which seemed to work fine. zlib must be installed in a standard
location, and gcc found it.

$ sudo make install

to install the lib into /usr/local/ (this was specified in the makefile,
and it's a good place for it)

$ make test
and
$ ./pngtest pngnow.png

Which both seemed to pass.

If you want to build a re-distributable version of matplotlib, you need
the static version of libpng, instead of the dynamic one. It doesn't use
./configure, so instead, I did a:

sudo make install-static

and that installed the *.a files in /usr/local/lib.

d) Numeric or numarray:

I already have Numeric installed, from Bob Ippolito's PIMP (MacPython
Package Manager) repostitory. (www.undefined.org/python)

2) Building matplotlib
---------------------------------------------------------
First, I took a look at the matplotlib setup.py. It had "auto" for the
back-end flags, so I thought I would give it a try that way:

$python setup.py build

If you have only the static version of libpng and libfreetype (*.a, and
not *.dylib) in /usr/local/lib (or anywhere else on your lib search
path), then it should link those statically.

That worked!
$ sudo python setup.py install

4) And now to test!

$python

import pylab

Could not open font file /Library/Fonts/NISC18030.ttf
No module named pygtk
PyGTK version 1.99.16 or greater is required to run the GTK Matplotlib
backends

This turns out to be because the matlabrc file sets the GTKAgg back end
as the default. You have two choices.

1) you can set the back end before importing pylab.

import matplotlib
matplotlib.use('Agg')
import pylab

This works fine

2) Edit the matplotlibrc file. I found it in:
/System/Library/Frameworks/Python.framework/Versions/2.3/share/matplotlib/.matplotlibrc

Change the line:
backend : GTKAgg # the default backend
to
backend : Agg # the default backend

And you're all set to make images for the web, etc.

I'm going to leave getting it to work with wxPython for another day.

3) Building a matplotlib Binary Package for OS-X:

First you need to make sure you've got libpng and libfreetype staticaly
linked. I did this by copying the headers and *.a files for them into a
directory I created called "StaticLibs", in the main matplot lib
directory (the one setup,py is in). You could just as easily put in
links, rather than copies, probably a better idea, actually.

Then I edited setupext.py, so that distutils would only look there:

basedir = {
     'win32' : ['win32_static',],
     'linux2' : ['/usr/local', '/usr',],
     'linux' : ['/usr/local', '/usr',],
# 'darwin' : ['/usr/local', '/usr', '/sw', '/usr/X11R6'],
     'darwin' : ['StaticLibs'],
     'freebsd4' : ['/usr/local', '/usr'],
     'sunos5' : [os.getenv('MPLIB_BASE') or '/usr/local',],
}

I'm talking to John Hunter about having a conditional Static setup in
the official setup.py to support this. This seemed to so the job.

To test, you can run:

$ otool -L *.so

in the matplotlib directory that is buried in the build directory. it
will tell you what libs the matplotlib extensions are linked to. They
should not be linked to libfreetype or libpng. libz is OK, it's included
with the stock OS-X.

Once you've got that built right, you can make an installer package with
Py2App.

This is a note from Bob Ippolito on the macPython mailing list:
"""use bdist_mpkg from py2app to make a redistributable .pkg installer
for it. After installing py2app, you should have a tool in
/usr/local/bin called "bdist_mpkg" that will Just Do It without any
setup.py modifications to the target lib... so go into the matplotlib
directory, type bdist_mpkg, and cross your fingers that a
dist/matplotlib-xx.pkg
"""
Here's exactly what I tried:

In the matplotlib directory (the same place as setup.py)

$ bdist_mpkg

and it worked!

Note: there are occasionally troubles with installing a newer matplotlib
over an older one. You may want to remove an older version before
installing, if you have one. To do this, delete:

/Library/Python/2.3/matplotlib/

Then click the mpkg. to install.

Building with tcl/TK:

I downloaded the BI (Batteries Included) installer for tcl/Tk Aqua. It's
got a lot of stuff I don't need, but it's only disk space. I then used
the MacPython PackageManager and the standard package list, and
installed Tkinter from there. It seemed to work.

Now back to the build cycle...Yeah it works!

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...