问题
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.
回答1:
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.
回答2:
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
回答3:
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
回答4:
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
来源:https://stackoverflow.com/questions/13754118/installing-pycairo-under-ubuntu