无法在 Mac OS X 上安装 matplotlib

发布于 2024-09-30 09:45:09 字数 1614 浏览 6 评论 0 原文

我正在尝试在 Mac OS X 上安装 matplotlib 以使用 Python 绘制应用程序。当我运行“python setup.py install”时,它给了我这样的错误负载: http://pastebin.com/u7fL37ic

一个简短的片段:

src/ft2font.cpp:2170: error: ‘FT_LOAD_TARGET_MONO’ was not declared in this scope
src/ft2font.cpp:2171: error: ‘FT_LOAD_TARGET_LCD’ was not declared in this scope
src/ft2font.cpp:2172: error: ‘FT_LOAD_TARGET_LCD_V’ was not declared in this scope
src/ft2font.cpp:2175: error: ‘_ft2Library’ was not declared in this scope
src/ft2font.cpp:2175: error: ‘FT_Init_FreeType’ was not declared in this scope
src/ft2font.cpp: In destructor ‘virtual ft2font_module::~ft2font_module()’:
src/ft2font.cpp:2186: error: ‘_ft2Library’ was not declared in this scope
src/ft2font.cpp:2186: error: ‘FT_Done_FreeType’ was not declared in this scope
lipo: can't figure out the architecture type of: /var/folders/Nj/Njnlp9qSF64sMESWcaDnk++++TI/-Tmp-//cchyYmM5.out
error: command 'gcc-4.0' failed with exit status 1

我使用 MacPorts 安装了 freetype,我认为这可以解决问题,但没有运气。给我和以前一样的错误。看起来找不到正确的 freetype 文件:

BUILDING MATPLOTLIB
        matplotlib: 1.0.0
            python: 2.6.5 (r265:79359, Mar 24 2010, 01:32:55)  [GCC
                    4.0.1 (Apple Inc. build 5493)]
          platform: darwin
REQUIRED DEPENDENCIES
             numpy: 1.5.0
         freetype2: found, but unknown version (no pkg-config)
                    * WARNING: Could not find 'freetype2' headers in any
                    * of '.', './freetype2'.

我应该将 freetype 文件放在哪里以便可以找到它们?现在他们在 /opt/local/lib

有什么想法吗?

I'm trying to install matplotlib for graphing applications in Python on Mac OS X. When I run "python setup.py install", it gives me this load of errors: http://pastebin.com/u7fL37ic.

A quick snippet:

src/ft2font.cpp:2170: error: ‘FT_LOAD_TARGET_MONO’ was not declared in this scope
src/ft2font.cpp:2171: error: ‘FT_LOAD_TARGET_LCD’ was not declared in this scope
src/ft2font.cpp:2172: error: ‘FT_LOAD_TARGET_LCD_V’ was not declared in this scope
src/ft2font.cpp:2175: error: ‘_ft2Library’ was not declared in this scope
src/ft2font.cpp:2175: error: ‘FT_Init_FreeType’ was not declared in this scope
src/ft2font.cpp: In destructor ‘virtual ft2font_module::~ft2font_module()’:
src/ft2font.cpp:2186: error: ‘_ft2Library’ was not declared in this scope
src/ft2font.cpp:2186: error: ‘FT_Done_FreeType’ was not declared in this scope
lipo: can't figure out the architecture type of: /var/folders/Nj/Njnlp9qSF64sMESWcaDnk++++TI/-Tmp-//cchyYmM5.out
error: command 'gcc-4.0' failed with exit status 1

I installed freetype using MacPorts, and I thought that would fix the issue, but no luck. Gives me same error as before. It looks like it can't find the right freetype files:

BUILDING MATPLOTLIB
        matplotlib: 1.0.0
            python: 2.6.5 (r265:79359, Mar 24 2010, 01:32:55)  [GCC
                    4.0.1 (Apple Inc. build 5493)]
          platform: darwin
REQUIRED DEPENDENCIES
             numpy: 1.5.0
         freetype2: found, but unknown version (no pkg-config)
                    * WARNING: Could not find 'freetype2' headers in any
                    * of '.', './freetype2'.

Where should I put the freetype files so that they can be found? Right now they're in /opt/local/lib

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

长亭外,古道边 2024-10-07 09:45:09

问题的根源在于 XCode 将 freetype 和 libpng 安装在非规范位置,即 /usr/X11,而不是 /usr 或 /usr/local。

已经给出的所有答案都通过手动或使用像 homebrew 这样的包管理器重新构建 freetype 和 libpng 来解决问题。

但是,您可以通过简单地将现有的 freetype/libpng 标头和库符号链接到 /usr/local 树中来编译 matplotlib:

sudo mkdir -p /usr/local/include
sudo ln -s /usr/X11/include/freetype2/freetype /usr/local/include/freetype
sudo ln -s /usr/X11/include/ft2build.h /usr/local/include/ft2build.h
sudo ln -s /usr/X11/include/png.h /usr/local/include/png.h
sudo ln -s /usr/X11/include/pngconf.h /usr/local/include/pngconf.h
sudo ln -s /usr/X11/include/pnglibconf.h /usr/local/include/pnglibconf.h
sudo mkdir -p /usr/local/lib
sudo ln -s /usr/X11/lib/libfreetype.dylib /usr/local/lib/libfreetype.dylib
sudo ln -s /usr/X11/lib/libpng.dylib /usr/local/lib/libpng.dylib

我更喜欢使用 pip 构建 python 包,所以我会使用:

sudo pip install matplotlib

如果您还没有有 pip,您可以使用 easy_install (OS X 附带)安装它:

sudo easy_install pip

我只在 10.7 (Lion) 上测试过它,但我怀疑它也适用于 10.6。

这有点麻烦,但我发现它是针对 OS X 附带的常用 Python 框架安装 matplotlib 的最简单方法。10.7 中的常用 Python 框架实际上非常好,并且包括,例如,一个 numpy-1.5.1 包链接到 Apple 优化的 BLAS 库(加速):

dyldinfo -dylibs /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/linalg/lapack_lite.so 
for arch x86_64:
attributes     dependent dylibs
            /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate
            /usr/lib/libSystem.B.dylib

The root of the problem is that freetype and libpng are installed in non-canonical locations by XCode, in /usr/X11 instead of /usr or /usr/local.

All of the answers already given address the problem by re-building freetype and libpng, either manually or using a package manager like homebrew.

You can, however, get matplotlib to compile by simply symlinking the existing freetype/libpng headers and libraries into the /usr/local tree with:

sudo mkdir -p /usr/local/include
sudo ln -s /usr/X11/include/freetype2/freetype /usr/local/include/freetype
sudo ln -s /usr/X11/include/ft2build.h /usr/local/include/ft2build.h
sudo ln -s /usr/X11/include/png.h /usr/local/include/png.h
sudo ln -s /usr/X11/include/pngconf.h /usr/local/include/pngconf.h
sudo ln -s /usr/X11/include/pnglibconf.h /usr/local/include/pnglibconf.h
sudo mkdir -p /usr/local/lib
sudo ln -s /usr/X11/lib/libfreetype.dylib /usr/local/lib/libfreetype.dylib
sudo ln -s /usr/X11/lib/libpng.dylib /usr/local/lib/libpng.dylib

I prefer to build python packages with pip, so I would then use:

sudo pip install matplotlib

If you don't already have pip, you can install it with easy_install (which comes with OS X):

sudo easy_install pip

I've only tested this on 10.7 (Lion) but I suspect it will also work with 10.6.

It is a little bit of a hack, but I've found it to be the easiest way to get matplotlib installed against the stock python framework that ships with OS X. The stock python framework in 10.7 is actually pretty good, and includes, for instance, a numpy-1.5.1 package that is linked against Apple's optimized BLAS library (Accelerate):

dyldinfo -dylibs /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/linalg/lapack_lite.so 
for arch x86_64:
attributes     dependent dylibs
            /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate
            /usr/lib/libSystem.B.dylib
寄人书 2024-10-07 09:45:09

旧的,但当我在 Snow Leopard 上遇到同样的问题时,它仍然出现在我的搜索中。

你说你正在使用自制程序,所以你需要

brew link freetype

在安装它后(使用“brew install freetype”)。

这解决了那个错误。我对 libpng 做了同样的事情,这导致安装成功。

Old, but still popped up in my search when I had the same problem on Snow Leopard.

You said you were using homebrew, so you need to

brew link freetype

after installing it (with "brew install freetype").

This got through that error. I had do the same thing with libpng, which resulted in a successful install.

北城挽邺 2024-10-07 09:45:09

我最近有了一台新的工作电脑(MacBook Pro OS 10.6.5),想在Python虚拟环境中安装numpy + scipy + matplotlib。我不是专家,但虚拟环境似乎允许您安装软件包,使它们与系统范围的软件包隔离,本质上是通过以巧妙的方式重新定义系统路径。因此,对于我正在处理的一个需要这些软件包的某些版本的项目,我可以安装它们一次并在那里完成该项目的所有工作,独立于我在环境之外所做的其他更改。

经过大量的试验和错误,我能够构建一个 Numpy 1.5.1、Scipy 0.8.0 和 Matplotlib 1.0.0 都完美运行的虚拟环境。具体方法如下:

首先,安装以下四个软件包:

(我是新用户,所以我无法发布这些链接,抱歉!)。

如果从源安装,请使用标准安装:

  • $ ./configure
  • $ make
  • $ sudo make install

接下来,下载 numpy、scipy 和 matplotlib 的源文件。

现在是时候在文件夹 TESTENV 中创建虚拟环境了:

$ virtualenv /path/to/dir/TESTENV

激活虚拟环境:

$ source 。 /path/to/dir/TESTENV/bin/activate

现在,python 软件包将安装在 TESTENV 中,就好像它是根安装目录一样。对我有用的是执行:

$ python setupegg.py install

in numpy、scipy 和 matplotlib 源文件夹(按顺序)。

希望有帮助!

I was given a new work computer recently (MacBook Pro OS 10.6.5), and wanted to install numpy + scipy + matplotlib in a Python virtual environment. I'm not an expert, but the virtual environment seems to allow you to install packages such that they are isolated from the system-wide packages, essentially by redefining the system path in a clever way. So, for one project I am working on that requires certain versions of these packages, I can install them once and do all of my work for that project there, independently of other changes I make outside the environment.

After a lot of trial and error, I was able to build a virtual environment with Numpy 1.5.1, Scipy 0.8.0, and Matplotlib 1.0.0 all running flawlessly. Here's how:

First, install the following four packages:

(I'm a new user so I can't post links to these, sorry!).

If you install from source, use a standard install:

  • $ ./configure
  • $ make
  • $ sudo make install

Next, download the source files for numpy, scipy, and matplotlib.

Now it's time to create a virtual environment in folder TESTENV:

$ virtualenv /path/to/dir/TESTENV

Activate the virtual environment:

$ source . /path/to/dir/TESTENV/bin/activate

Now, python packages will be installed within TESTENV as if it were the root installation directory. What worked for me was to execute:

$ python setupegg.py install

in the numpy, scipy, and matplotlib source folders (in that order).

Hope that helps!

蹲墙角沉默 2024-10-07 09:45:09

请尝试此处的说明。我的笔记此处

Try the instuctions here. My notes here.

时间你老了 2024-10-07 09:45:09

我在尝试安装 matplotlib 时遇到了同样的问题。在尝试了上面的一些解决方案之后,我就运行了

brew install freetype

,安装很顺利,直到遇到一个 png.h not find 。我运行

brew install libpng

安装完成并安装了 matplotlib。

(在操作系统 X 10.8.4 上)

I was having the same problem when trying to install matplotlib. After trying some of the above solution, I just ran

brew install freetype

then, the installation went well until it ran into a png.h not found. I ran

brew install libpng

The installation finished and matplotlib was installed.

(on os X 10.8.4)

不弃不离 2024-10-07 09:45:09

我是这样做的:

$ sudo make -f make.osx fetch deps mpl_build mpl_install

这会将其安装在 /lib/python2.6/site-packages 中,只需将其内容移动到 /Library/Python/2.6/site-packages/ 为了一致性。

Here's how I did it:

$ sudo make -f make.osx fetch deps mpl_build mpl_install

This will install it in /lib/python2.6/site-packages, just move its contents to /Library/Python/2.6/site-packages/ for consistency.

何以笙箫默 2024-10-07 09:45:09

我遇到了类似的错误 - 你缺少 libfreetype 的开发文件 - 在我的 linux 机器上 - 这是 libfreetype6-dev

在我安装了这个 pip 后,它就完成了工作。

I got a similar error - you're missing the development files for libfreetype - on my linux machine - this is libfreetype6-dev

After I installed this pip did it's job.

早乙女 2024-10-07 09:45:09

每次构建 matplotlib 时都会遇到这个问题。我的解决方案:

export CFLAGS=-I/usr/X11/include/freetype2
python setup.py install

Running into this every time I build matplotlib. My solution:

export CFLAGS=-I/usr/X11/include/freetype2
python setup.py install
九厘米的零° 2024-10-07 09:45:09

我强烈推荐 StrongInference Scipy Superpack。它可以与 10.6 Snow Leopard 上内置的 Apple 提供的 Python 配合使用,现在也可以与 10.9 配合使用。它对 32 位和 64 位安装都很友好。它不需要安装单独的 Python 发行版或 Macports 或 Fink 等包管理器。

首先从此页面下载 shell 脚本来使用它。然后:

sh superpack_10.6_2011.03.07.sh

或者,将 superpack_10.6_2011.03.07.sh 替换为最新的 shell 脚本的名称,因为它们会不时更新。

要使用它,请确保输入 ipython 而不是 python!

I would highly recommend the StrongInference Scipy Superpack. It works with the built-in Apple supplied Python on 10.6 Snow Leopard, and this is now working with 10.9. It's friendly to both 32-bit and 64-bit installs. It does not require installing a separate Python distribution or package managers like Macports or Fink.

Use it by first downloading the shell script from this page. Then:

sh superpack_10.6_2011.03.07.sh

Or, replace superpack_10.6_2011.03.07.sh with the name of the latest shell script as they update it from time to time.

To use it, make sure you type in ipython and not python!

森罗 2024-10-07 09:45:09

我按照这个页面的说明。我陷入了困境

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

然后我做了:

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

通过在终端中输入来检查我的安装:

python
import matplotlib
print matplotlib.__version__
print matplotlib.__file__

我得到了版本 0.10.0 dev(截至撰写本文时)和路径 /usr/local/Cellar/...

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/...

莫多说 2024-10-07 09:45:09

我喜欢使用啤酒,但前三个解释对我来说都不起作用或没有吸引力。然而,我确实看了更多,发现了这个brew友好的解释和解决方案:

http://jholewinski.org/blog/installing-matplotlib-on-os-x-10-7-with-homebrew/

摘要:雪豹上的 libpng 不友好与 matplotlib 相关的术语。您可以手动安装未发布的 matplotlib 来解决这个问题:

brew install python
brew install gfortran
brew install pkg-config
easy_install pip
pip install numpy
git clone https://github.com/matplotlib/matplotlib.git
cd matplotlib
python setup.py build
python setup.py install

I like using the brew, and none of the top three explanations worked or were enticing to me. However, I did look some more, and found this brew friendly explanation and solution:

http://jholewinski.org/blog/installing-matplotlib-on-os-x-10-7-with-homebrew/

Summary: libpng on Snow Leopard isn't on friendly terms with matplotlib. You can manually install the un-released matplotlib to work around it:

brew install python
brew install gfortran
brew install pkg-config
easy_install pip
pip install numpy
git clone https://github.com/matplotlib/matplotlib.git
cd matplotlib
python setup.py build
python setup.py install
榆西 2024-10-07 09:45:09

尝试将 freetype2 符号链接到 freetype:

ln -s /usr/local/opt/freetype/include/freetype2/ /usr/local/include/freetype

Try symlinking freetype2 to freetype:

ln -s /usr/local/opt/freetype/include/freetype2/ /usr/local/include/freetype
薄情伤 2024-10-07 09:45:09

您还可以考虑使用 Enthought 发行版(对于非商业用途甚至免费)
完全安装完毕,没有任何困难
http://www.enthought.com/products/getepd.php
(我与 Enthought 没有任何关系 - 我只是一个满意的用户)

you may also consider using the Enthought distribution (which comes even free for non-commercial usage)
It comes fully installed without any difficulty
http://www.enthought.com/products/getepd.php
(I have no relationship with Enthought whatsoever - I'm just a satisfied user)

何其悲哀 2024-10-07 09:45:09

我能够在不修改我的路径等的情况下让它工作。看来我的问题是使用非brew python时找不到freetype库(与brew一起安装)

brew install python
brew install freetype
# maybe more dependencies

然后使用brew python创建一个virtualenv(没有明确指定到brew python的路径我发现brew virtualenv仍然会使用默认的OSX /usr/bin/python):

/usr/local/bin/virtualenv -p /usr/local/bin/python env
source env/bin/activate
pip install matplotlib

I was able to get this to work without modifying my PATH etc. It seems my problem was the freetype library (installed with brew) not being found when using a non-brew python

brew install python
brew install freetype
# maybe more dependencies

Then create a virtualenv using the brew python (without explicitly specifying the path to the brew python I found that the brew virtualenv would still use the default OSX /usr/bin/python):

/usr/local/bin/virtualenv -p /usr/local/bin/python env
source env/bin/activate
pip install matplotlib
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文