How to install pycairo on osx?
Asked Answered
W

6

13

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?

Walter answered 30/9, 2009 at 21:53 Comment(1)
Update: I cp'ed all the .h files from the pixman directory to cairo's. An ugly brute-force thing, but it seemed to work: 'make ; sudo make install' seem to work fine. I still get "Requested 'cairo >= 1.8.8' but version of cairo is 1.0.4" when trying to install pycairo, though. It thinks I have cairo 1.0.4, and ignores the new one. Any idea why? How I can fix that?Walter
W
14

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:

PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH.

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

Whipstitch answered 6/5, 2015 at 23:2 Comment(3)
If you're using python 3, you can use "brew install py3cairo" instead.Displume
Error: invalid option: --use-clang; Then: brew install cairo --cc=clang; Then: Error: cairo: no bottle available!Contrabassoon
brew install py2cairo is invalid.Writeup
W
7

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 setup.py install
    

This should do it...

Walter answered 30/9, 2009 at 22:29 Comment(2)
I think you have problems because you are mixing macports fink and your own code together - use one of these only ;) effecitively each of these is equivalent to the Linix's own packaging system. The reason I say this is that /opt/local/bin would be from Macports and not your own code which by default would be /usr/local/binNocturnal
Can you please add from where and which file to download for each of those libraries?Mudcat
C
7

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 python.org 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.

Clavicle answered 28/11, 2009 at 7:26 Comment(4)
I tried your suggestion and it worked successfully. Thank you very much. I think my main problem was that I am unaware of the mechanisms and conventions of macports and macos in general. I have read macports introductions and documentation from macports.org but I never realised the version number was used in the title (I assumed it somehow used resolved to the latest version or something)Stew
Yes, the MacPorts python naming convention is rather confusing. If they had started by using py24- instead of py-, it might be less so. Glad it all worked!Clavicle
How do you get cairo.HAS_QUARTZ_SURFACE to yield 1?Elegancy
vy32, You're not likely to get an answer by asking an unrelated question in a comment. Create a new question and supply enough context so people can give an intelligent answer.Clavicle
B
3

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.

Bundesrat answered 28/11, 2009 at 6:52 Comment(6)
Here (#1501366) is another person with a similar problemBundesrat
If you are not careful, using easy_install like that could further complicate matters by bringing the Apple-supplied python into the picture and it won't help solve the root problem.Clavicle
I took Akusete to mean that he wanted to use pycairo from his Python2.6.4 framework build (his step 1). If he gets that working he could ditch all the MacPorts python stuff and avoid this problem in the future. But your all-MacPorts solution is good too. Is there any reason to prefer it?Bundesrat
Getting all the dependent libraries straight and linked properly can be tricky (I haven't looked at the pycairo installation files to see if they check for libraries in the MacPorts locations). More importantly, by default, a plain easy_install command will most likely invoke the Apple-supplied /usr/bin/easy_install command which will install pycairo in the site-packages directory of the Apple-supplied default Python, not the python.org 2.6.4; to do that, you'll need to install a separate easy_install (from setuptools or Distribute) for that python.Clavicle
How do you get cairo.HAS_QUARTZ_SURFACE to yield 1?Elegancy
Processing pycairo-1.10.0.tar.bz2 error: Couldn't find a setup script in /tmp/easy_install-tooeLq/pycairo-1.10.0.tar.bz2Irwin
C
2

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).

Caryopsis answered 11/1, 2010 at 21:22 Comment(0)
E
1

Step 1: Run this from terminal ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null

Step 2: brew install cairo

Step 3: pip install pycairo

Erudite answered 22/11, 2019 at 13:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.