为 Python 3.6 安装 py3cairo

Posted

技术标签:

【中文标题】为 Python 3.6 安装 py3cairo【英文标题】:Install py3cairo for Python 3.6 【发布时间】:2017-02-21 03:14:06 【问题描述】:

我正在尝试安装 pygobject,但其中一个依赖项是 py3cairo。我已经安装了它以与 Python 3.4 一起使用,但现在我想将它与 Python 3.6 一起使用。

我知道我可以用sudo apt-get install python3-cairo 安装它,但它说它已经安装了:

$ sudo apt-get install python3-cairo
Reading package lists... Done
Building dependency tree       
Reading state information... Done
python3-cairo is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.

然而,

Python 3.6.0 (default, Feb 20 2017, 17:34:58) 
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gi'
>>> import cairo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cairo'
>>> quit()
brandon@bjd2385:~/Downloads$ python3.4
Python 3.4.2 (default, Oct  8 2014, 10:45:20) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>> import cairo

尝试从源代码构建/安装它是丑陋的,因为我遇到了所有种类的问题:

$ PYTHON="python3.6" ./waf configure
  ./options()
Setting top to                           : /home/brandon/Downloads/pycairo-1.10.0 
Setting out to                           : /home/brandon/Downloads/pycairo-1.10.0/build_directory 
  ./configure()
Checking for 'gcc' (c compiler)          : ok 
Checking for program python              : python3.6 
python executable 'python3.6' different from sys.executable '/usr/local/bin/python3.6'
Checking for python version              : (3, 6, 0, 'final', 0) 
Traceback (most recent call last):
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Scripting.py", line 93, in waf_entry_point
    run_commands()
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Scripting.py", line 145, in run_commands
    run_command(cmd_name)
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Scripting.py", line 138, in run_command
    ctx.execute()
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Configure.py", line 124, in execute
    super(ConfigurationContext,self).execute()
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Context.py", line 87, in execute
    self.recurse([os.path.dirname(g_module.root_path)])
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Context.py", line 127, in recurse
    user_function(self)
  File "/home/brandon/Downloads/pycairo-1.10.0/wscript", line 29, in configure
    ctx.check_python_headers()
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Configure.py", line 217, in fun
    return f(*k,**kw)
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Tools/python.py", line 146, in check_python_headers
    result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in LIBDIR'%name)
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Configure.py", line 217, in fun
    return f(*k,**kw)
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Tools/c_config.py", line 357, in check
    ret=self.run_c_code(*k,**kw)
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Configure.py", line 217, in fun
    return f(*k,**kw)
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Tools/c_config.py", line 435, in run_c_code
    bld.compile()
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Build.py", line 190, in compile
    self.store()
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Utils.py", line 300, in f
    ret=fun(*k,**kw)
  File "/home/brandon/Downloads/pycairo-1.10.0/.waf3-1.6.4-e3c1e08604b18a10567cfcd2d02eb6e6/waflib/Build.py", line 164, in store
    cPickle.dump(data,f)
AttributeError: Can't pickle local object 'Context.__init__.<locals>.node_class'
Checking for library python3.6 in LIBDIR : 

如何安装 py3cairo 并解决这些问题?

【问题讨论】:

【参考方案1】:

我正在尝试做同样的事情,在 Slackware 14.2 上用 python3.6 编译 pycairo。我得到和你一样的错误, 并且提到的各种 waf 补丁都没有工作。

我确实在这一追求中取得了进步。 slackware-current 发行版有一个似乎可以运行的 waf 脚本。在http://ftp.slackware.com/pub/slackware/slackware-current/source/l/pycairo/

此脚本中缺少您提到的上述错误,但是当它尝试编译时弹出另一个错误,并在 cairomodule.c 中出现错误。

slackware-current 构建几乎成功,但仍然失败并出现编译错误。也许对库有更多经验的人可以修复它。

【讨论】:

这很有帮助,我试试看会发生什么。

以上是关于为 Python 3.6 安装 py3cairo的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Windows 10 上为 python 3.6 安装 dlib?

如何在Python 3.6上安装PIP?

python 3.6 setup

安装GDAL for Python 3.6时的ImportError

如何为python 3.6安装wxPython phoenix

在Ubuntu 16.04 安装python3.6 环境并设置为默认