如何安装Python的Cairo?

3

我刚开始学习Python3,已经创建了虚拟环境。我尝试使用pip命令安装pycairo包,但需要先安装Python Cairo。请参考以下信息:

pip install git+http://anongit.freedesktop.org/git/pycairo
Downloading/unpacking git+http://anongit.freedesktop.org/git/pycairo
  Cloning http://anongit.freedesktop.org/git/pycairo to /tmp/pip-0c_foz-build
  Running setup.py egg_info for package from git+http://anongit.freedesktop.org/git/pycairo
    cairo >= 1.10.2  Successful

Installing collected packages: pycairo
  Running setup.py install for pycairo
    cairo >= 1.10.2  Successful
    building 'cairo._cairo' extension
    gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/python3.2mu -c src/cairomodule.c -o build/temp.linux-i686-3.2/src/cairomodule.o
    src/cairomodule.c:22:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    Complete output from command /home/nyros/Desktop/NewWeb/venv/bin/python3 -c "import setuptools;__file__='/tmp/pip-0c_foz-build/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-lo0egc-record/install-record.txt --single-version-externally-managed --install-headers /home/nyros/Desktop/NewWeb/venv/include/site/python3.2:
    cairo >= 1.10.2  Successful

creating py3cairo.pc

creating src/config.h

running install

running build

running build_ext

building 'cairo._cairo' extension

creating build

creating build/temp.linux-i686-3.2

creating build/temp.linux-i686-3.2/src

gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12 -I/usr/include/python3.2mu -c src/cairomodule.c -o build/temp.linux-i686-3.2/src/cairomodule.o

src/cairomodule.c:22:20: fatal error: Python.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

----------------------------------------
Command /home/nyros/Desktop/NewWeb/venv/bin/python3 -c "import setuptools;__file__='/tmp/pip-0c_foz-build/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-lo0egc-record/install-record.txt --single-version-externally-managed --install-headers /home/nyros/Desktop/NewWeb/venv/include/site/python3.2 failed with error code 1 in /tmp/pip-0c_foz-build
Storing complete log in /home/nyros/.pip/pip.log

但是我遇到了错误,请帮我解决问题。谢谢。

你能否发布命令 find /usr/include -name Python.h 的结果。谢谢。 - Michał Fita
感谢回复。结果是 /usr/include/python2.7_d/Python.h /usr/include/python2.7/Python.h /usr/include/python2.6/Python.h /usr/include/python2.6_d/Python.h - dhana
所以,PIP完成的编译过程出现了问题。如果您查看gcc调用,您会发现-I/usr/include/python3.2mu。您的Python.h存在于许多目录中,但没有指向gcc的目录。奇怪的是,您正在尝试针对Python 3.x进行编译,而您的系统仅有Python 2.x的头文件... - Michał Fita
谢谢,我已经通过sudo apt-get install python3-dev解决了我的问题。并且将Python.h文件附加到python3.2mu中。 - dhana
1个回答

5
我认为这可能会解决你的问题:
sudo apt-get install python3-dev
但我不能保证这能100%地解决问题 :-)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接