How to install pycairo on osx?

I am trying to install the pycairo (Python bindings for the cairo graphics library) under OSX.

I started with

easy_install pycairo

and got:

Requested 'cairo >= 1.8.8' but version of cairo is 1.0.4

error: Setup script exited with Error: cairo >= 1.8.8 not found

So I went to cairo's site and downloaded the latest package (1.8.8) of cairo, and also the latest package of something called pixman (both source packages -- couldn't find osx binaries)

unzipped both, each in own directory. for pixman, the regular ./configure ; make ; sudo make install worked just find for cairo, ./configure seemed to work, but make failed with:

In file included from cairo-analysis-surface.c:37:
cairoint.h:71:20: error: pixman.h: No such file or directory

What am I doing wrong?

And why do I have to struggle so much to get a software library to work on an os that "just works"? Why isn't darwin more like linux?

Asked by: Richard116 | Posted: 06-12-2021

Answer 1

If you already have homebrew, these two commands should be helpful:

$ brew install cairo --use-clang 
$ brew install py2cairo

For a non-Homebrew installed Python, set the PYTHONPATH to find pycairo. You can set your PYTHONPATH in your .bashrc/.profile/.whatever to the following:


I personally didn't need to use this last part but it might help you.

Answered by: Lenny153 | Posted: 07-01-2022

Answer 2

It appears you are mixing various install options here. The MacPorts package system port install command should automatically pull in all the dependencies needed for a particular package so the trick is to start with the right top-level project. For python packages, MacPorts has a general convention currently: packages that start with py- are for python 2.4, those with py25- are for 2.5, and py26- for 2.6. There are currently py-cairo, py25-cairo, and py26-cairo packages available in MacPorts.

By choosing py-cairo you picked the python2.4 version and you'll probably find that MacPorts built and installed a python2.4 for you (linked at /opt/local/bin/python2.4) and, if you launch it, you'll probably find that you can import cairo there. Now that may be OK for your needs but Python 2.4 is quite old and no longer supported so, if you're just starting, it might be better to start with Python 2.6, one of the two current versions of Python. To do so, all you should need to do is:

sudo port install py26-cairo

That should bring in any missing dependencies, mainly the MacPorts python2.6, which you can run from /opt/local/bin/python2.6. You may want to change your $PATH in your shell startup script, probably .bash_profile, to put /opt/local/bin early on the search path.

Because installing Cairo and its python bindings seems to be fairly complex, it should be easier and better to stick to using a complete MacPorts solution for this. That does mean you've needlessly (and harmlessly) installed a couple of Python instances that you won't need. But if you do want to clean things up a bit, you can easily remove the MacPorts python24 with:

sudo port uninstall py-cairo python24

Completely removing the installed python is more complicated. I've explained the process here. But there's no pressing need to remove either as long as you keep your paths straight.

Answered by: Paul867 | Posted: 07-01-2022

Answer 3

Ok. I solved it. Putting solution here for future reference, it might help someone.

Basically, the whole ports/fink system is a bit messed up, and osx doesn't really play nice with the linux-y world.

So, the steps I needed to install pycairo on OSX were:

  • download the latest source versions of pixman, cairo, pycairo
  • extract everything. Then:

    cd PIXMAN_DIR ; ./configure ; make ; sudo make install 
    cd CAIRO_DIR ; cp PIXMAN_DIR/pixman/*.h . ; ./configure ; make ; sudo make install
    cd PYCAYRO_DIR; locate cairo.pc 

    hopefully, several locations are returned. choose the most likely one (one with newest cairo). For me it was "/opt/local/lib/pkgconfig/cairo.pc" and do:

    export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig/

    after this, still in PYCAIRO_DIR, do:

    python install

This should do it...

Answered by: Michael377 | Posted: 07-01-2022

Answer 4

The port command installs the library for the darwinports python installation, which is different to the framework build (so steps 2 and 3 shouldn't work). Try sudo easy_install pycairo instead (although your step 4 should be equivalent to this).

Look at which python too, to check that you are in fact running the python you think you are.

Answered by: Blake629 | Posted: 07-01-2022

Answer 5

On Mac OS you can have multiple Python versions installed. You can have even more if you decide to install Python via Fink or MacPorts. When you compile libraries from the source, you should make sure they point to the correct installation.

I currently have Python 2.5.1 and Python 2.6.4 installed on my machine, which I can call via python2.5 and python respectively. They live in two different folders: /System/Library/Frameworks/Python.framework/Versions/2.5and /Library/Frameworks/Python.framework/Versions/2.6

I was running into a similar problem when compiling pycairo 1.8.8 from the tarball. The INSTALL file in this case is your friend, as it contains the correct instructions to avoid potential version conflicts. You basically need to specify the correct prefix so that the package will be installed in the correct folder.

$ python -c "import sys; print sys.prefix"
  # make a note of the python prefix
$ ./configure --prefix=[python_prefix]
$ make
$ make install       # may require superuser access

Running these instructions with python2.5 and python you will be able to correctly install pycairo for both versions (or for any version installed via MacPorts / Fink).

Answered by: Kimberly600 | Posted: 07-01-2022

Answer 6

Step 1: Run this from terminal ruby -e "$(curl -fsSL" < /dev/null 2> /dev/null

Step 2: brew install cairo

Step 3: pip install pycairo

Answered by: Adelaide381 | Posted: 07-01-2022

Similar questions

how to install pycairo for python 3 on Ubuntu 10.04

i am trying to install pycairo 1.10.0 for use with my custom-build python 3.1. however, sudo /flower/bin/easy_install-3.1 pycairo fails with XXX@XXXX:/adventures$ sudo /flower/bin/easy_install-3.1 pycairo install_dir /flower/lib/python3.1/site-packages/ Searching for pycairo Reading Reading Best match:...

how to install pycairo for python 3 on Ubuntu 10.04

i am trying to install pycairo 1.10.0 for use with my custom-build python 3.1. however, sudo /flower/bin/easy_install-3.1 pycairo fails with XXX@XXXX:/adventures$ sudo /flower/bin/easy_install-3.1 pycairo install_dir /flower/lib/python3.1/site-packages/ Searching for pycairo Reading Reading Best match:...

How to install PyCairo 1.10 on Mac OSX with default python

Has anyone installed pycairo 1.10 on the mac using the new waf build? Its failing on can't find python headers.

How do you install PyCairo (Cairo for Python) on Windows?

I spent hours this afternoon trying to find a straightforward tutorial for installing PyCairo on Windows. The Cairo project itself does not maintain Windows binaries, they must be dowloaded elsehere (e.g. The process is also complicated further apparently by the fact...

python - Why can't I install pycairo on windows 10

This is the error log: Running install for pycairo ... error ERROR: Command errored out with exit status 1: command: 'c:\anaconda3\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '&quot;'&quot;'C:\\Users\\ANASIM~1\\AppData\\Local\\Temp\\pip-install-1lo1lxwq\\pycairo\\'&quot;'&quot;'; __file__='&quot;'&quot;'C:\\Users\\ANASIM~1\\AppData\\Local\\Temp\\pip-install-1lo1lxwq\\...

macos - python install on leopard

I'll admit I'm completely dumbed by python install. Can someone help me on how to install module I want to play with PyGame, PyOpenGL etc. So I install them, but I everytime I type "import pygame" error message shows up. here's my environment so far. In .bash_profile PATH=${PATH}:/System/Library/Frameworks/Python.framework/Versions/Current/bin Using easy_install PyO...

python - How can I install pyCurl?

I used libcurl with no problems and used pyCurl once in the past. Now i want to set it up on my machine and dev. However i have no idea how to do it. I rather not DL libcirl files and compile that along with pycurl, i want to know the simplest method. I have libcurl installed on my machine. I am on Windows. I tried DLing the sources and use pycurl setup script, but I had no luck.

python - where does django install in ubuntu

I am looking for the file for django. I tried whereis and find, but I get a lot of dirs.

python - Install mysqldb on snow leopard

I am trying to get started on working with Python on Django I am by profession a PHP developer and have been told to set up django and python on my current apache and mysql setup however I am having trouble getting the Mysqldb module for python to work, I must of followed about 6 different set of instructions, I am running snow leopard and have mysql installed natively it is not part of MAMP or similar. Please can some tel...

Install python 2.6 in CentOS

I have a shell that runs CentOS. For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4. From what I've read, a number of things will break if you upgrade to 2.5. I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred it, and did a ./configure --prefix=/opt which is where I want it to end ...

How to install 64-bit Python on Solaris?

I am trying to install Python 2.6 on Solaris by building the source on Solaris machine. I installed one this way and it appears that it is 32-bit. I downloaded some source tar ball as Linux or Unix for this purpose. Everything works well but I need 64-bit Python. I looked up the Python download site and there is no sepa...

macos - Install PyObjC on Python 2.6 on OS X 10.5?

OS X 10.5.8 came with Python 2.5, and had PyObjC already installed. I installed Python 2.6 from the site, and PyObjC isn't there. I can't find a download to install PyObjC on my Python 2.6 install. Is checking out the PyObjC trunk and trying to build it my only choice? Will that work "out of the box"?

python - How to install numpy and scipy on Windows XP

python - How do I install SciPy on 64 bit Windows?

How do I install SciPy on my system? For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: (is direct download URL, 2310144 bytes). Running the SciPy superpack installer results in this message in a dialog box:...

What should I install in order to be able to use GTK in Python on Ubuntu?

In my source code I have: import gtk But when I run the script with python3 command I get the following error. What package should I install to get it working? Edit: my bad. here is the error: ImportError: No module named gtk Edit2: Thanks for the answer, But I'm still getting an error message. Take a look at the following...

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python