Has anyone installed pycairo 1.10 on the mac using the new waf build? Its failing on can't find python headers.
3 Answers
I think waf is seriously broken for Mac OS X :(
Here's how it worked for me. After python waf configure
failed to find Python.h, I looked through the config.log file located in build_directory and found out that the true cause of failure was incompatible architecture. The waf script tries to build a simple source file with CPython calls in it using i386 architecture. It fails to do so, because my python is built for the x86_64 architecture.
I guess, you could rebuild python as a universal binary, I haven't tried that. It is possible, however, to build pycairo using the x86_64 architecture. Here's how.
My setup:
$ python --version
Python 2.7.2
$ type python
python is /usr/local/bin/python
$ file /usr/local/bin/python
/usr/local/bin/python: Mach-O 64-bit executable x86_64
$ brew --version
0.8
Importrant: my python version is built for the x86_64
architecture. Make sure it is also the case for you before performing the steps described below.
brew stands for homebrew. You must use it instead of fink or MacPorts in order for the following steps to work for you.
Now, to install cairo and pycairo I do the following:
brew install cairo
(version 1.10.2 as of today)Get pycairo source for python 2.x (if you get a snapshot, it is named py2cairo, whereas pycairo now requires python 3.x). I used the source from master branch (commit f3435910d8f5365b45ebd4216f4043383c9e3e19)
Open
wscript
in your editor of choice, locate the lineenv = ctx.env
in the functionconfigure
and add the following line below itenv.append_unique('CFLAGS', ['-arch', 'x86_64'])
Save the file
Run these commands in your terminal:
export CC=/usr/bin/gcc
export PKG_CONFIG_PATH=/usr/local/Cellar/cairo/1.10.2/lib/pkgconfig/
Important: the latter path will only work for you if you installed cairo via homebrew
Then run the waf commands described in the pycairo's INSTALL file:
python waf configure
python waf build
python waf install
This should do it. If it doesn't work for you, I think it's better to raise the topic on the pycairo mailing list (if it has one).

- 21,988
- 13
- 81
- 109

- 7,287
- 2
- 31
- 41
-
Haha I tried this as I wanted to check out brew and it worked. Thanks. – Aug 30 '11 at 01:40
-
Minor nitpick - you're not actually using the default python? – jabley Sep 26 '11 at 22:31
-
@jabley default python is too old. Version 2.7 added lots of useful little things — http://www.python.org/getit/releases/2.7/ – Alexei Sholik Sep 27 '11 at 17:37
-
2I had to follow some additional steps to properly set LD_LIBRARY_PATH and a few other env vars, via instructions here: http://www.niconomicon.net/blog/2011/10/09/2120.wrestling.python.snow.leopard – llimllib Nov 17 '11 at 07:28
-
2I followed these steps but got the error `Cairo pkgconfig requires xcb-shm package which is not installed`. I changed the `PKG_CONFIG_PATH` to `export PKG_CONFIG_PATH=/usr/local/Cellar/cairo/
/lib/pkgconfig/:/opt/X11/lib/pkgconfig` and the configure step worked. Source: https://github.com/mxcl/homebrew/issues/14123 – Jonathan Drake Feb 23 '13 at 21:35
For anyone coming back to this, I was able to get py2cairo installed on OSX Lion with a slightly different approach, based on llimllib's link. Hope this helps:
python waf clean
export PYTHONPATH=/Library/Frameworks/Python.framework/Versions/2.7/
export LD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/2.7/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/2.7/lib:$LD_LIBRARY_PATH
export LINKFLAGS='-search_dylibs_first -L /Library/Frameworks/Python.framework/Versions/2.7/lib/'
export ARCHFLAGS='-arch x86_64'
export CC=/usr/bin/gcc-4.2
export PKG_CONFIG_PATH=/usr/local/Cellar/cairo/1.10.2/lib/pkgconfig/
python waf configure --prefix=$PYTHONPATH
python waf build
python waf install
-
2Worked for me using the Mac Ports cairo library, just didn't set the pkg_config_path the above flags where enough – Dr BDO Adams Dec 06 '12 at 16:05
-
1
android's step almost works. one needs to use (from llimllib):
export ARCHFLAGS='-arch x86_64'
in step 5, and then python waf install
can succeed.

- 9,998
- 4
- 42
- 62

- 3,159
- 3
- 34
- 32