简体   繁体   English

在mac osx lion中安装MatplotLib

[英]Installing MatplotLib in mac osx lion

I was trying to install matplotlib in Mac OSX Lion. 我试图在Mac OSX Lion中安装matplotlib。 Tried to used the binary that is in the sourcefourge site, but I got this error: "matplotlib requires System Python 2.7 to install". 试图使用sourcefourge站点中的二进制文件,但我得到了这个错误:“matplotlib需要安装System Python 2.7”。

I went to the Terminal and typed python --version and its check the requirements. 我去了终端并输入了python --version并检查了要求。

After this I tried to used the pip, and while doing so é got the following error: 在此之后我尝试使用pip,并且这样做é得到以下错误:

"src/_image.cpp:908: error: invalid use of incomplete type 'struct png_info_def'" “src / _image.cpp:908:错误:无效使用不完整类型'struct png_info_def'”

Can you give me clues in how to install it? 你能告诉我如何安装它的线索吗?

Many thanks. 非常感谢。

EDIT: I found a way, without having to install a new version of python: 编辑:我找到了一种方法,无需安装新版本的python:

http://the.taoofmac.com/space/blog/2011/07/24/2222 http://the.taoofmac.com/space/blog/2011/07/24/2222

This is because of a change in the API for libpng v1.5 (which is included with Mac OSX Lion). 这是因为libpng v1.5(包含在Mac OSX Lion中)的API发生了变化。 The changes has already been pushed upstream, so you will need to compile from the upstream repository until the next release. 这些更改已经被推送到上游,因此您需要从上游存储库进行编译,直到下一个版本。

You can follow the instructions on http://jholewinski.wordpress.com/2011/07/21/installing-matplotlib-on-os-x-10-7-with-homebrew/ 您可以按照http://jholewinski.wordpress.com/2011/07/21/installing-matplotlib-on-os-x-10-7-with-homebrew/上的说明进行操作。

I followed this page's instructions . 我按照这个页面的说明进行操作 I got stuck at 我被卡住了

pip install -e git+https://github.com/matplotlib/matplotlib#egg=matplotlib-dev

Then I did: 然后我做了:

git clone https://github.com/matplotlib/matplotlib.git
cd matplotlib
python setup.py build
python setup.py install

Checked my installation by typing in terminal: 通过键入终端检查我的安装:

python
import matplotlib
print matplotlib.__version__
print matplotlib.__file__

I got version 0.10.0 dev (as of this writing) and path /usr/local/Cellar/... 我得到版本0.10.0 dev(截至本文撰写时)和路径/ usr / local / Cellar / ...

You can try with an "official" python distribution, apple might have tweaked the supplied one. 你可以尝试使用“官方”python发行版,苹果可能已经调整了提供的版本。 You can find the 2.7 here: http://www.python.org/download/ You might have to re-install numpy as well afterwords: http://sourceforge.net/projects/numpy/files/NumPy/1.6.1/ 你可以在这里找到2.7: http//www.python.org/download/你可能不得不重新安装numpy以及后续词: http//sourceforge.net/projects/numpy/files/NumPy/1.6.1 /

I would suggest to install scipy as well Let me know if it works ;) 我建议安装scipy以便让我知道它是否有效;)

I would recommend using macports , it should take care of dependencies and would be indepedent of the system python version. 我建议使用macports ,它应该处理依赖关系,并且将独立于系统python版本。

EDIT : Just a few clarifications, taking into account comments to this answer. 编辑 :只是一些澄清,考虑到对这个答案的评论。

Why use macports (or another installer)? 为什么要使用macports(或其他安装程序)? Because they take care of dependencies, provide functionality to uninstall and switch between versions (I've used the latter successfully for gcc and python). 因为它们负责依赖,提供卸载和在版本之间切换的功能(我已经成功地将后者用于gcc和python)。 And because the default installation location is not the system executable location. 并且因为默认安装位置不是系统可执行位置。 Overriding the system python can break applications that rely on it (this is certainly true in many Linux distributions, maybe less so on mac OS X). 覆盖系统python可能会破坏依赖它的应用程序(在许多Linux发行版中都是如此,在mac OS X上可能更​​少)。

When is it particularly useful? 什么时候特别有用? When you want to install on top of a version of python that is different to system python, and when you have non-python extensions (C, C++, Fortran...). 当你想安装在与python不同的python版本之上时,以及你有非python扩展(C,C ++,Fortran ......)时。

What's the down side? 什么是不好的一面? As @Trond has mentioned in the comments, it is good if you're OK with default compilations of packages. 正如@Trond在评论中提到的那样,如果您对包的默认编译没有问题,那就太好了。 You don't have a handle over configuration or compiler flags as you would if you built from source. 您没有像从源构建时那样处理配置或编译器标志。

A good alternative to macports is fink , which seems to give you more control (build from source). macports的一个很好的替代品就是fink ,这似乎可以让你获得更多的控制权(从源代码构建)。 I am not sure it is completely ready for mac OS X Lion yet. 我不确定它是否完全适用于mac OS X Lion。

I know it will take a lot more time, but I would reccomend installing python, numpy, and matplotlib from source to ensure that you have consistency in your system. 我知道这将花费更多的时间,但我会建议从源代码安装python,numpy和matplotlib,以确保您的系统具有一致性。 From the error it could look like you have a problem with libPNG support. 从错误中可能看起来你有libPNG支持的问题。 I have a written a " How to install python dev tools on Mac OSX " that you may find useful. 我写了一篇“ 如何在Mac OSX上安装python开发工具 ”,你可能会发现它很有用。 It contains directions for how to install python, numpy, matplotlib and all necessary dependencies. 它包含如何安装python,numpy,matplotlib和所有必要依赖项的说明。 I understand you are working with Python 2.7 and the directions I am listing is for Python 2.6.5, but it would be the same approach. 我知道你正在使用Python 2.7,我列出的方向是针对Python 2.6.5,但它将是相同的方法。 Hope you get it to work. 希望你能开始工作。

You could just install the Python 2.6 version of Matplotlib, assuming that Python2.6 is included with Lion (py2.5 & 2.6 are included with Mac OS 10.6 "Snow Leopard" - try typing python2.6 to find out if that version is installed.). 您可以安装Python 2.6版本的Matplotlib,假设Lion2中包含Python2.6(py2.5和2.6包含在Mac OS 10.6“Snow Leopard”中 - 尝试输入python2.6以查明是否安装了该版本)。

On MacPorts you do this via something like: 在MacPorts上,您可以通过以下方式执行此操作:

sudo port install py26-matplotlib

where py26-... (or py25-..., py27-... etc.) indicates which python version it is meant for. 其中py26 -...(或py25 -...,py27 -...等)表示它的用途是哪个python版本。 (check the Pallet/ports list to get the correct package name, in case I guessed wrong) (检查托盘/端口列表以获取正确的包名称,以防我猜错了)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM