سؤال

For some reason I can't get python to find cairo.

When I did ./waf configure I got

Setting top to                           : /home/user/pycairo/py2cairo-1.10.0
Setting out to                           : /home/user/pycairo/py2cairo-1.10.0/build_directory
./configure()
Checking for 'gcc' (c compiler)          : ok
Checking for program python              : /usr/bin/python
Checking for python version              : (2, 7, 2, 'final', 0)
Checking for library python2.7           : yes
Checking for program python2.7-config    : /usr/bin/python2.7-config
Checking for header Python.h             : yes
Checking for program pkg-config          : /usr/bin/pkg-config
Checking for 'cairo' >= 1.10.0           : yes
Configuration:
PREFIX                                   : /usr/local
LIBDIR                                   : /usr/local/lib

So next I ran ./waf install.

tried

import cairo
ImportError: No module named cairo

Now I am pretty stumped on what to do next. I checked /usr/local/lib/python2.7/site-packages and it is there but that is the only package there. I also noticed "dist-packages" which I think that is where it's meant to go?

any help is greatly appreciated.

هل كانت مفيدة؟

المحلول

What is wrong with using the packaged version, with full Ubuntu support?

http://packages.ubuntu.com/python-cairo

Python bindings for the Cairo vector graphics library

http://packages.ubuntu.com/python-gi-cairo

Python Cairo bindings for the GObject library

The "latest" way of using Cairo should be via gobject introspection (second package):

from gi.repository import cairo

which uses mostly auto-generated API from the GI repository that is consistent across various programming languages.

نصائح أخرى

I like to suggest its cffi-based version which is more common it seems and can be installed on Ubuntu 17.10 at least from apt-get (or apt)

sudo apt-get install python-cairocffi python3-cairocffi

Check out this link, all the instructions are given here.

git clone https://github.com/atizo/pycairo/
cd pycairo 
run python setup.py install

You will be able to import cairo in python after this

in Ubuntu 14.04 I did this:

cd /home/username/Programming/Repositories/
sudo git clone git://git.cairographics.org/git/pycairo
sudo apt-get install libcairo2-dev libjpeg-dev  libgif-dev
cd pycairo
sudo python3 setup.py install

go to this url for more information OR:

Debian / Ubuntu

sudo apt-get install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info

macOS

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Windows

Dear Windows user, please follow these steps carefully.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top