Python pip 安装 matplotlib:“没有 pkg-config”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13979916/
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
pip install matplotlib: "no pkg-config"
提问by kjo
When I run pip install matplotlib(within a virtualenv), the first lines of output are:
当我运行时pip install matplotlib(在 virtualenv 中),输出的第一行是:
Downloading/unpacking matplotlib
Running setup.py egg_info for package matplotlib
basedirlist is: ['/usr/local/', '/usr', '/usr/X11', '/opt/local']
============================================================================
BUILDING MATPLOTLIB
matplotlib: 1.2.0
python: 2.7.3 (default, Dec 14 2012, 13:31:05) [GCC 4.2.1
(Apple Inc. build 5666) (dot 3)]
platform: darwin
REQUIRED DEPENDENCIES
numpy: 1.6.2
freetype2: found, but unknown version (no pkg-config)
OPTIONAL BACKEND DEPENDENCIES
libpng: found, but unknown version (no pkg-config)
Tkinter: Tkinter: 81008, Tk: 8.5, Tcl: 8.5
Gtk+: no
* Building for Gtk+ requires pygtk; you must be able
* to "import gtk" in your build/install environment
Mac OS X native: yes
Qt: no
Qt4: no
PySide: no
Cairo: no
<snip>
Note
笔记
- the "no pkg-config", and
- the missing Qt library.
- “无 pkg-config”,以及
- 缺少的 Qt 库。
First, contrary to what the output above says, pkg-configisin fact installed and on the PATH:
首先,相反的是上面的输出说,pkg-config是在实际上安装在PATH:
% pkg-config --version
0.27.1
% which pkg-config
/usr/local/bin/pkg-config
Second, qtis available in the same directory where freetypeand libpngwere found:
其次,qt是在同一个目录中可用的freetype和libpng被发现:
% ls -l /usr/local/opt/{freetype,libpng,qt} | cut -c43-
/usr/local/opt/freetype -> ../Cellar/freetype/2.4.10/
/usr/local/opt/libpng -> ../Cellar/libpng/1.5.13/
/usr/local/opt/qt -> ../Cellar/qt/4.8.4/
My question has three parts:
我的问题分为三个部分:
- Where does
pip install matplotlibget thatbasedirlist(3rd line of the output above)?- What must I do differently so that
pip install matplotlibwill findpkg-config?- What must I do differently so that
pip install matplotlibwill findqt?
- 从哪里
pip install matplotlib得到basedirlist(上面输出的第三行)?- 我必须做些什么不同的事情
pip install matplotlib才能找到pkg-config?- 我必须做些什么不同的事情
pip install matplotlib才能找到qt?
回答by Leo Mizuhara
I can't ask your specific questions, but my pip install matplotlib looked a lot like yours the other day. After five hours of slamming my head against the wall, this solution worked for me (from practicalcomputing.org
我不能问你的具体问题,但前几天我的 pip install matplotlib 看起来很像你的。在将我的头撞在墙上五个小时后,这个解决方案对我有用(来自实用计算.org
I got this set of commands to set up simlinks:
我得到了这组命令来设置 simlinks:
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
It doesn't quite solve all your issues, but it solved my pkg-config issue (among others). Perhaps a similar link would help with QT.
它并不能完全解决您的所有问题,但它解决了我的 pkg-config 问题(以及其他问题)。也许类似的链接会对 QT 有所帮助。
回答by John Haberstroh
I had an almost identical error. I looked through the errors further down, and it seems like the problem was with freetype2.
我有一个几乎相同的错误。我进一步查看了错误,似乎问题出在 freetype2 上。
I've had similarly frustrating issues with other packages that use freetype. For me, the compile error came from the following:
我在使用 freetype 的其他软件包中也遇到过类似的令人沮丧的问题。对我来说,编译错误来自以下内容:
/usr/local/include/freetype2/freetype/*.h are the freetype files.
/usr/local/include/ freetype2/freetype/*.h 是 freetype 文件。
/usr/local/include is the search directory.
/usr/local/include 是搜索目录。
-Ifreetype/*.h is the flag passed to the compiler.
-Ifreetype/*.h 是传递给编译器的标志。
The problem is subtle, but I was able to get matplotlib to compile (which honestly, is approximately all I really care about) by copying /usr/local/include/freetype2/freetype -> /usr/local/include/freetype.
问题很微妙,但我能够通过复制 /usr/local/include/freetype2/freetype -> /usr/local/include/freetype 来编译 matplotlib(老实说,这几乎是我真正关心的所有内容)。
Hopefully this will help anyone who stumbles across this!
希望这会帮助任何偶然发现此问题的人!
回答by Arun Jayapal
Just install freetype fonts to get matplotlib.
只需安装 freetype 字体即可获得 matplotlib。
sudo apt-get install freetype*
All the matplotlib files are installed to /usr/local/lib/python2.7/site-packages/. Even if you want to install using pip installer, you need to fix freetype font problem, which can be done as stated above.
所有 matplotlib 文件都安装到 /usr/local/lib/python2.7/site-packages/。即使你想使用 pip installer 安装,你也需要修复 freetype 字体问题,这可以按照上面说的来完成。
回答by jasterm007
Old question, but wanted to leave some possibly helpful crumbs.
老问题,但想留下一些可能有用的面包屑。
I just dealt with a somewhat similar issue on Ubuntu 12.04 after trying to manually install an application that relied on a set of Python bindings that were manually installed within a virtualenv. The Python bindings were clearly installed in an appropriate place within my virtualenv, but the installer simply couldn't find them with pkg-config.
在尝试手动安装依赖于在 virtualenv 中手动安装的一组 Python 绑定的应用程序后,我刚刚在 Ubuntu 12.04 上处理了一个有点类似的问题。Python 绑定显然安装在我的 virtualenv 中的适当位置,但安装程序根本无法通过pkg-config.
So to answer the original questions:
所以要回答原来的问题:
- Where does pip install matplotlib get that basedirlist (3rd line of the output above)?
- Not sure, but I'm guessing this might be something matplotlib's setup.py hardcoded after it detected your OS/distribution/version.
- What must I do differently so that pip install matplotlib will find pkg-config?
- I'm fairly certain it's finding
pkg-configjust fine; it's just not detecting any useful information forfreetype2andlibpng.
- I'm fairly certain it's finding
- What must I do differently so that pip install matplotlib will find qt?
- This is all based on experience on Ubuntu 12.04.
- Installing
python-qt4globally and creating a virtualenv with--system-site-packagesenabled should make matplotlib happy, even if it means littering your global environment with modules. But I haven't been able to get pip to do anything useful when trying to install PyQt4 or python-qt in a virtualenv. - Installing
libqt4-devshould also alleviate any dependency issues when building anything relying on Qt4. - If that didn't work, and others' answers here didn't help, this may shed some light on why pip is unhappy:
man pkg-configOn most systems, pkg-config looks in /usr/lib/pkgconfig, /usr/share/pkgconfig, /usr/local/lib/pkgconfig and /usr/local/share/pkgconfig for these files. It will additionally look in the colon-separated (on Windows, semicolon-separated) list of directories specified by the PKG_CONFIG_PATH environment variable.
pkg-configis looking for *.pc files; the fact that you found those dependencies installed somewhere doesn't meanpkg-configwill find any *.pc files in those directories.- As the man page indicates, if your packages are installed in funny places, you need to set
PKG_CONFIG_PATHappropriately. - If you've perchance installed your packages into your virtualenv, then you need to make sure your virtualenv's activate/deactivate commands update PKG_CONFIG_PATH appropriately. The only way I got this to work was to modify the
bin/activatescript in my virtualenv.- You can pretty much copy the existing code that maintains an
_OLD_VIRTUAL_PATHbefore updatingPATHupon activation, and reverting back to_OLD_VIRTUAL_PATHupon deactivation - Note that the existing code isn't perfect as of the time of this post, since if your
PKG_CONFIG_PATHwas blank to begin with, you need a bit more logic to make sure it gets cleared upon deactivation
- You can pretty much copy the existing code that maintains an
- pip install matplotlib 从哪里获得那个 basedirlist(上面输出的第 3 行)?
- 不确定,但我猜这可能是 matplotlib 的 setup.py 在检测到您的操作系统/发行版/版本后硬编码的内容。
- 我必须做些什么不同的事情才能让 pip install matplotlib 找到 pkg-config?
- 我相当肯定它发现
pkg-config很好;它只是没有检测到任何有用的信息freetype2和libpng。
- 我相当肯定它发现
- 我必须做些什么不同的事情才能让 pip install matplotlib 找到 qt?
- 这都是基于 Ubuntu 12.04 的经验。
python-qt4全局安装并创建一个--system-site-packages启用的 virtualenv应该会让 matplotlib 高兴,即使这意味着用模块乱扔你的全局环境。但是在尝试在 virtualenv 中安装 PyQt4 或 python-qt 时,我无法让 pip 做任何有用的事情。libqt4-dev在构建依赖于 Qt4 的任何东西时,安装还应该缓解任何依赖问题。- 如果这不起作用,而其他人的答案也没有帮助,这可能会说明为什么 pip 不高兴:
man pkg-config在大多数系统上,pkg-config 在 /usr/lib/pkgconfig、/usr/share/pkgconfig、/usr/local/lib/pkgconfig 和 /usr/local/share/pkgconfig 中查找这些文件。它还将查看由 PKG_CONFIG_PATH 环境变量指定的以冒号分隔(在 Windows 上,以分号分隔)的目录列表。
pkg-config正在寻找 *.pc 文件;您发现这些依赖项安装在某处的事实并不意味着pkg-config会在这些目录中找到任何 *.pc 文件。- 正如手册页所示,如果您的软件包安装在有趣的地方,您需要进行
PKG_CONFIG_PATH适当的设置。 - 如果您可能已将软件包安装到您的 virtualenv 中,那么您需要确保您的 virtualenv 的激活/停用命令适当地更新 PKG_CONFIG_PATH。
bin/activate我让它工作的唯一方法是修改我的 virtualenv 中的脚本。- 您几乎可以复制在激活时
_OLD_VIRTUAL_PATH更新之前维护的现有代码PATH,并_OLD_VIRTUAL_PATH在停用时恢复到 - 请注意,截至本文发布时,现有代码并不完美,因为如果您
PKG_CONFIG_PATH一开始是空白的,您需要更多的逻辑来确保它在停用时被清除
- 您几乎可以复制在激活时
回答by Grzegorz Pawe?czuk
sudo apt-get build-dep python-matplotlib
回答by zhaoqing
For me (Mac OS), I use which pkg-configto check installation. If not, use brew to install and it works:
对于我(Mac OS),我which pkg-config用来检查安装。如果没有,请使用 brew 安装,它可以工作:
brew install pkg-config

