macos 如何在 osx 上安装 pycairo?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1500866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to install pycairo on osx?
提问by Yoav
I am trying to install the pycairo(Python bindings for the cairo graphics library) under OSX.
我正在尝试在 OSX 下安装pycairo(cairo 图形库的Python 绑定)。
I started with
我开始了
easy_install pycairo
and got:
并得到:
Requested 'cairo >= 1.8.8' but version of cairo is 1.0.4
error: Setup script exited with Error: cairo >= 1.8.8 not found
So I went to cairo's site and downloaded the latest package (1.8.8) of cairo, and also the latest package of something called pixman (both source packages -- couldn't find osx binaries)
所以我去了 cairo 的网站并下载了 cairo 的最新包(1.8.8),以及最新的 pixman 包(两个源包——都找不到 osx 二进制文件)
unzipped both, each in own directory.
for pixman, the regular ./configure ; make ; sudo make install
worked just find
for cairo, ./configure seemed to work, but make failed with:
解压缩两者,每个都在自己的目录中。对于 pixman,常规./configure ; make ; sudo make install
工作只是为 cairo 找到,./configure 似乎工作,但 make 失败:
In file included from cairo-analysis-surface.c:37:
cairoint.h:71:20: error: pixman.h: No such file or directory
What am I doing wrong?
我究竟做错了什么?
And why do I have to struggle so much to get a software library to work on an os that "just works"? Why isn't darwin more like linux?
为什么我必须如此努力才能让软件库在“正常工作”的操作系统上工作?为什么 darwin 不更像 linux?
回答by Mina
I found thisinstruction very helpful and much less confusing. I am on Yosemite and it worked very well for me. This instruction uses homebrew to install. So if you already have homebrew, these two commands should be helpful:
我发现这个说明非常有帮助,而且不那么令人困惑。我在优胜美地,对我来说效果很好。本说明使用自制软件进行安装。因此,如果您已经有自制软件,那么这两个命令应该会有所帮助:
$ brew install cairo --use-clang
$ brew install py2cairo
For a non-Homebrew installed Python, this instruction suggest to set the PYTHONPATH to find pycairo. You can set your PYTHONPATH in your .bashrc/.profile/.whatever to the following:
对于非 Homebrew 安装的 Python,此指令建议设置 PYTHONPATH 以查找 pycairo。您可以将 .bashrc/.profile/.whatever 中的 PYTHONPATH 设置为以下内容:
PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH.
I personally didn't need to use this last part of the instruction but it might help you.
我个人不需要使用说明的最后一部分,但它可能对您有所帮助。
回答by Yoav
Ok. I solved it. Putting solution here for future reference, it might help someone.
行。我解决了。将解决方案放在这里以供将来参考,它可能会对某人有所帮助。
Basically, the whole ports/fink system is a bit messed up, and osx doesn't really play nice with the linux-y world.
基本上,整个ports/fink 系统都有些混乱,而且osx 在linux-y 世界中并没有真正发挥作用。
So, the steps I needed to install pycairo on OSX were:
因此,我在 OSX 上安装 pycairo 所需的步骤是:
- download the latest source versions of pixman, cairo, pycairo
extract everything. Then:
cd PIXMAN_DIR ; ./configure ; make ; sudo make install cd CAIRO_DIR ; cp PIXMAN_DIR/pixman/*.h . ; ./configure ; make ; sudo make install cd PYCAYRO_DIR; locate cairo.pc
hopefully, several locations are returned. choose the most likely one (one with newest cairo). For me it was "/opt/local/lib/pkgconfig/cairo.pc" and do:
export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig/
after this, still in PYCAIRO_DIR, do:
python setup.py install
- 下载最新版本的 pixman、cairo、pycairo
提取一切。然后:
cd PIXMAN_DIR ; ./configure ; make ; sudo make install cd CAIRO_DIR ; cp PIXMAN_DIR/pixman/*.h . ; ./configure ; make ; sudo make install cd PYCAYRO_DIR; locate cairo.pc
希望返回几个位置。选择最有可能的一个(最新的开罗)。对我来说,它是“/opt/local/lib/pkgconfig/cairo.pc”并执行:
export PKG_CONFIG_PATH=/opt/local/lib/pkgconfig/
在此之后,仍在 PYCAIRO_DIR 中,执行:
python setup.py install
This should do it...
这个应该可以...
回答by Ned Deily
It appears you are mixing various install options here. The MacPorts package system port install
command should automatically pull in all the dependencies needed for a particular package so the trick is to start with the right top-level project. For python packages, MacPorts has a general convention currently: packages that start with py-
are for python 2.4, those with py25-
are for 2.5, and py26-
for 2.6. There are currently py-cairo
, py25-cairo
, and py26-cairo
packages available in MacPorts.
看来您在这里混合了各种安装选项。MacPorts 包系统port install
命令应该自动拉入特定包所需的所有依赖项,所以诀窍是从正确的顶级项目开始。对于 python 包,MacPorts 目前有一个通用约定:以 开头的包py-
用于 python 2.4,带有py25-
2.5 和py26-
2.6 的包。目前py-cairo
,py25-cairo
和py26-cairo
在MacPorts的可用的软件包。
By choosing py-cairo
you picked the python2.4 version and you'll probably find that MacPorts built and installed a python2.4 for you (linked at /opt/local/bin/python2.4
) and, if you launch it, you'll probably find that you can import cairo there. Now that maybe OK for your needs but Python 2.4 is quite old and no longer supported so, if you're just starting, it might be better to start with Python 2.6, one of the two current versions of Python. To do so, all you should need to do is:
通过选择py-cairo
您选择了 python2.4 版本,您可能会发现 MacPorts 为您构建并安装了一个 python2.4(链接在/opt/local/bin/python2.4
),如果您启动它,您可能会发现您可以在那里导入 cairo。现在这可能满足您的需求,但 Python 2.4 已经很旧并且不再受支持,因此,如果您刚刚开始,最好从 Python 2.6(Python 的两个当前版本之一)开始。为此,您需要做的就是:
sudo port install py26-cairo
That should bring in any missing dependencies, mainly the MacPorts python2.6, which you can run from /opt/local/bin/python2.6
. You may want to change your $PATH
in your shell startup script, probably .bash_profile, to put /opt/local/bin
early on the search path.
这应该会引入任何缺失的依赖项,主要是 MacPorts python2.6,您可以从/opt/local/bin/python2.6
. 您可能希望更改您$PATH
的 shell 启动脚本,可能是 .bash_profile,以便/opt/local/bin
尽早将其置于搜索路径中。
Because installing Cairo and its python bindings seems to be fairly complex, it should be easier and better to stick to using a complete MacPorts solution for this. That does mean you've needlessly (and harmlessly) installed a couple of Python instances that you won't need. But if you do want to clean things up a bit, you can easily remove the MacPorts python24 with:
因为安装 Cairo 及其 python 绑定似乎相当复杂,所以坚持使用完整的 MacPorts 解决方案应该更容易、更好。这确实意味着您已经不必要地(并且无害地)安装了几个您不需要的 Python 实例。但是,如果您确实想稍微清理一下,您可以使用以下命令轻松删除 MacPorts python24:
sudo port uninstall py-cairo python24
Completely removing the python.org installed python is more complicated. I've explained the process here. But there's no pressing need to remove either as long as you keep your paths straight.
完全删除 python.org 安装的 python 更复杂。我已经在这里解释了这个过程。但是,只要您保持路径笔直,就没有紧迫的需要移除。
回答by Michael Dunn
The port
command installs the library for the darwinports python installation, which is different to the framework build (so steps 2 and 3 shouldn't work). Try sudo easy_install pycairo
instead (although your step 4 should be equivalent to this).
该port
命令为 darwinports python 安装安装库,这与框架构建不同(因此第 2 步和第 3 步不应该起作用)。尝试sudo easy_install pycairo
改用(尽管您的第 4 步应该与此等效)。
Look at which python
too, to check that you are in fact running the python you think you are.
也看看which python
,以检查您实际上是否正在运行您认为自己正在运行的python。
回答by radrat
On Mac OS you can have multiple Python versions installed. You can have even more if you decide to install Python via Fink or MacPorts. When you compile libraries from the source, you should make sure they point to the correct installation.
在 Mac OS 上,您可以安装多个 Python 版本。如果您决定通过 Fink 或 MacPorts 安装 Python,您可以获得更多。从源代码编译库时,应确保它们指向正确的安装。
I currently have Python 2.5.1 and Python 2.6.4 installed on my machine, which I can call via python2.5
and python
respectively. They live in two different folders:
/System/Library/Frameworks/Python.framework/Versions/2.5
and /Library/Frameworks/Python.framework/Versions/2.6
我目前在我的机器上安装了 Python 2.5.1 和 Python 2.6.4,我可以分别通过python2.5
和调用它们python
。它们位于两个不同的文件夹中:
/System/Library/Frameworks/Python.framework/Versions/2.5
和/Library/Frameworks/Python.framework/Versions/2.6
I was running into a similar problem when compiling pycairo 1.8.8 from the tarball. The INSTALL
file in this case is your friend, as it contains the correct instructions to avoid potential version conflicts. You basically need to specify the correct prefix so that the package will be installed in the correct folder.
从 tarball 编译 pycairo 1.8.8 时,我遇到了类似的问题。INSTALL
在这种情况下,该文件是您的朋友,因为它包含避免潜在版本冲突的正确说明。您基本上需要指定正确的前缀,以便将包安装在正确的文件夹中。
$ python -c "import sys; print sys.prefix" # make a note of the python prefix $ ./configure --prefix=[python_prefix] $ make $ make install # may require superuser access
Running these instructions with python2.5
and python
you will be able to correctly install pycairo for both versions (or for any version installed via MacPorts / Fink).
运行这些指示python2.5
和python
你将能够获得两个版本的正确安装pycairo(或通过使用MacPorts / Fink安装任何版本)。
回答by seralouk
Step 1:Run this from terminal ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
第 1 步:从终端运行它ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
Step 2:brew install cairo
第2步:brew install cairo
Step 3:pip install pycairo
第 3 步:pip install pycairo