如何使用Homebrew来安装像Py2Cairo这样的Python库

这是我到目前为止所做的:

我已经安装了Homebrew:

/usr/bin/ruby -e "$(/usr/bin/curl -fsSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"

然后python:brew安装python

然后py2cairo:brew install py2cairo

这两个似乎都正确安装,当我键入我得到的python:usr / local / bin / python我相信是自制的版本.

我编辑了我的道路,许多Homebrew指南都建议:

export PATH=/usr/local/bin:/usr/local/share/python:$PATH

这是我从echo $PATH得到的:/usr/local / bin:/usr/local / share / python:/usr/bin:/ bin:/usr/sbin:/ sbin:/usr/local / bin:/usr/X11 / bin中

我也可以键入python –version并得到python 2.7.3这似乎是正确的,因为如果我看/usr/local/Cellar/py2cairo/1.10.0/README它说:

Dependencies
------------
    cairo   >= 1.10.0
    Python  >= 2.6

然而,毕竟,我仍然无法将py2cairo库导入到python中.这是我尝试时得到的:

Sal:~ Lockyer$python
Python 2.7.3 (default, May  6 2012, 13:47:31) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairo
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort trap: 6

我认为大多数人使用pip或easy_install这种事情,但我不认为py2cairo是受支持的.当我运行pip-2.7安装py2cairo时,我得到的是:

Downloading/unpacking py2cairo
  Could not find any downloads that satisfy the requirement py2cairo
No distributions at all found for py2cairo
Storing complete log in /Users/Lockyer/Library/Logs/pip.log

我想我一定只是错过了一个最后一步,我以某种方式揭示了python从哪里导入图书馆,我忘了添加一些东西到我的路上?

当我运行ls -l /usr/local / bin / python时,这是我得到的

lrwxr-xr-x  1 Lockyer  admin  33  6 May 13:48 /usr/local/bin/python -> ../Cellar/python/2.7.3/bin/python

当我运行otool -L /usr/local/Cellar/py2cairo/1.10.0/lib/python2.7/site-packages/cairo/_cairo.so时,我得到的是:

/usr/local/Cellar/py2cairo/1.10.0/lib/python2.7/site-packages/cairo/_cairo.so:
    /private/tmp/homebrew-py2cairo-1.10.0-BtmY/py2cairo-1.10.0/build_directory/src/_cairo.so (compatibility version 0.0.0, current version 0.0.0)
    /usr/local/Cellar/cairo/1.10.2/lib/libcairo.2.dylib (compatibility version 11003.0.0, current version 11003.2.0)
    /System/Library/Frameworks/Python.framework/Versions/2.7/Python (compatibility version 2.7.0, current version 2.7.1)
    /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1094.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)

将/System/Library/Frameworks/Python.framework/Versions移动到我的桌面,再次运行brew install py2cairo似乎已经修复了错误.很高兴知道为什么它是建立在狮子的Python,虽然它似乎不是第一个在路上…

我偶然发现了同样的错误.通过一些搜索,我发现 project on GitHub已经在 project on GitHub的问题页面上被检测到.

这似乎是一个waf处理库导入的问题,我完全不了解.修复已经提交并正在等待批准.

如果有人在接受修复之前还遇到这个问题,可以按照this answer提出的命令安装py2cairo的固定公式.

brew rm -f py2cairo
brew install  https://raw.githubusercontent.com/2bits/homebrew/15b3e67/Library/Formula/py2cairo.rb

当修复被批准时,一个简单的brew更新应该解决问题.

相关文章
相关标签/搜索