xcode 安装 Matplotlib 时出错 - clang

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12910126/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:49:53  来源:igfitidea点击:

Errors installing Matplotlib - clang

pythonxcodemacosmatplotlibclang

提问by elksie5000

I've tried to install Matplot lib but I'm still struggling to get past errors.

我已经尝试安装 Matplot lib,但我仍在努力克服错误。

I've installed numpy and psipy but have the following error when I use easy_install (there is a similar error with pip).

我已经安装了 numpy 和 psipy,但是在使用 easy_install 时出现以下错误(pip 也有类似的错误)。

And yes, I've installed the command line tools in Xcode in a bid to solve the 'gcc-4.2 not found' problem.

是的,我已经在 Xcode 中安装了命令行工具,以解决“找不到 gcc-4.2”的问题。

pymods ['pylab']
packages ['matplotlib', 'matplotlib.backends', 'matplotlib.backends.qt4_editor',          

'matplotlib.projections', 'matplotlib.testing', 'matplotlib.testing.jpl_units',     

'matplotlib.tests', 'mpl_toolkits', 'mpl_toolkits.mplot3d', 'mpl_toolkits.axes_grid',     

'mpl_toolkits.axes_grid1', 'mpl_toolkits.axisartist', 'matplotlib.sphinxext',    

'matplotlib.tri', 'matplotlib.delaunay', 'pytz', 'dateutil', 'dateutil.zoneinfo']
warning: no files found matching 'KNOWN_BUGS'
warning: no files found matching 'INTERACTIVE'
warning: no files found matching 'MANIFEST'
warning: no files found matching '__init__.py'
warning: no files found matching 'examples/data/*'
warning: no files found matching 'lib/mpl_toolkits'
warning: no files found matching 'LICENSE*' under directory 'license'
gcc-4.2 not found, using clang instead
In file included from src/ft2font.cpp:3:
src/ft2font.h:16:10: fatal error: 'ft2build.h' file not found
#include <ft2build.h>
     ^
1 error generated.
error: Setup script exited with error: command 'clang' failed with exit status 1

回答by BigHandsome

I recently had this issue as well, but I was using pip. If you have homebrewinstalled you can solve it by running the following commands:

我最近也遇到了这个问题,但我使用的是 pip。如果您安装了自制软件,则可以通过运行以下命令来解决它:

brew install freetype
brew install libpng
brew link freetype
pip install git+https://github.com/matplotlib/matplotlib.git#egg=matplotlib-dev

回答by willwade

theres actually an easier way! First see if X11 libraries are installed (ls /usr/X11/include)

其实还有更简单的方法!首先查看是否安装了X11库(ls /usr/X11/include)

If they aren't you may need to install X11

如果不是,您可能需要安装 X11

If they are then a simple fix is this:

如果他们是那么一个简单的修复是这样的:

cd /usr/X11/include
sudo ln -s freetype2/freetype

Basically for some reason its looking for the freetype library at /usr/X11 and its actually in the subfolder in freetype2. Odd - but it does then compile this way.

基本上出于某种原因,它在 /usr/X11 中寻找 freetype 库,实际上它在 freetype2 的子文件夹中。奇怪 - 但它确实以这种方式编译。

回答by m33n

I did the following and it worked for me

我做了以下工作,它对我有用

sudo apt install libfreetype6-dev
pip install matplotlib

回答by m33n

You're missing freetype2, or at least the development version. It's looking for ft2build.h, which is a freetype2 header file.

您缺少 freetype2,或者至少缺少开发版本。它正在寻找ft2build.h,这是一个 freetype2 头文件。

You can either try installing freetype2from source, or just a package manager like macports, fink or homebrew to install it (for package managers, make sure you pick the development version if that's available).

您可以尝试从源代码安装freetype2,或者仅使用 macports、fink 或 homebrew 之类的包管理器来安装它(对于包管理器,请确保选择可用的开发版本)。

But if you are going the route of package managers, you could also install matplotlib that way. And there may be binaries for OS X that include freetype2, so that may be even easier than installing from source.

但是如果你要走包管理器的路线,你也可以这样安装 matplotlib。并且可能有包含 freetype2 的 OS X 二进制文件,因此这可能比从源代码安装更容易。

The reason easy_install and pip don't install freetype2 for you, is that it's not a Python package.

easy_install 和 pip 不为您安装 freetype2 的原因是它不是 Python 包。

== Correction ==

==更正==

freetype2 should be available, not just where easy_install or pip expect it. On my Mac, I can ft2build.h in /usr/X11/include. So, you'll need to set the CFLAGSvariable to that directory (and probably LDFLAGSto /usr/X11/lib`) to get the installation working. Now, with easy_install and pip, I'm not 100% sure how to do that. Try e.g.

freetype2 应该可用,而不仅仅是在 easy_install 或 pip 期望的地方。在我的 Mac 上,我可以将 ft2build.h 放在 /usr/X11/include 中。因此,您需要将CFLAGS变量设置为该目录(并且可能设置LDFLAGS为 /usr/X11/lib`)以使安装工作。现在,使用 easy_install 和 pip,我不是 100% 确定如何做到这一点。尝试例如

CFLAGS=-I/usr/X11/include LDFLAGS=-L/usr/X11/lib easy_install matplotlib

Or, just download the matplotlib source, adjust setup.pyand build it yourself.

或者,只需下载 matplotlib 源代码,自行调整setup.py和构建即可。