简体   繁体   English

pip 安装 matplotlib:“没有 pkg​​-config”

[英]pip install matplotlib: "no pkg-config"

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笔记

  1. the "no pkg-config", and “无 pkg-config”,以及
  2. the missing Qt library.缺少的 Qt 库。

First, contrary to what the output above says, pkg-config is in fact installed and on the PATH :首先,相反的是上面的输出指出, pkg-config其实在安装,并在PATH

% pkg-config --version
0.27.1
% which pkg-config
/usr/local/bin/pkg-config

Second, qt is available in the same directory where freetype and libpng were found:其次, qt在找到freetypelibpng的同一目录中可用:

% 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:我的问题分为三个部分:

  1. Where does pip install matplotlib get that basedirlist (3rd line of the output above)? pip install matplotlib从哪里获得那个basedirlist (上面输出的第 3 行)?
  2. What must I do differently so that pip install matplotlib will find pkg-config ?我必须做些什么不同的事情才能pip install matplotlib找到pkg-config
  3. What must I do differently so that pip install matplotlib will find qt ?我必须做些什么不同的事情才能让pip install matplotlib找到qt
sudo apt-get build-dep python-matplotlib

On Mac OS: I use which pkg-config to check installation.在 Mac OS 上:我使用which pkg-config来检查安装。 If not, use brew to install and it works:如果没有,请使用 brew 安装,它可以工作:

brew install pkg-config

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/.所有 matplotlib 文件都安装到 /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.即使你想使用 pip installer 安装,你也需要修复 freetype 字体问题,这可以按照上面说的来完成。

I can't ask your specific questions, but my pip install matplotlib looked a lot like yours the other day.我不能问你的具体问题,但我的 pip install matplotlib 前几天看起来很像你的。 After five hours of slamming my head against the wall, this solution worked for me (from practicalcomputing.org在将我的头撞在墙上五个小时后,这个解决方案对我有用(来自practicecomputing.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).它并不能完全解决您的所有问题,但它解决了我的 pkg-config 问题(以及其他问题)。 Perhaps a similar link would help with QT.也许类似的链接会对 QT 有所帮助。

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.在尝试手动安装依赖于在 virtualenv 中手动安装的一组 Python 绑定的应用程序后,我刚刚在 Ubuntu 12.04 上处理了一个有点类似的问题。 The Python bindings were clearly installed in an appropriate place within my virtualenv, but the installer simply couldn't find them with pkg-config . Python 绑定显然安装在我的 virtualenv 中的适当位置,但安装程序根本无法使用pkg-config找到它们。

So to answer the original questions:所以要回答原来的问题:

  1. Where does pip install matplotlib get that basedirlist (3rd line of the output above)? pip install matplotlib 从哪里获得那个 basedirlist(上面输出的第 3 行)?
    • Not sure, but I'm guessing this might be something matplotlib's setup.py hardcoded after it detected your OS/distribution/version.不确定,但我猜这可能是 matplotlib 的 setup.py 在检测到您的操作系统/发行版/版本后硬编码的内容。
  2. What must I do differently so that pip install matplotlib will find pkg-config?我必须做些什么不同的事情才能让 pip install matplotlib 找到 pkg-config?
    • I'm fairly certain it's finding pkg-config just fine;我相当肯定它找到pkg-config就好了; it's just not detecting any useful information for freetype2 and libpng .它只是没有检测到freetype2libpng任何有用信息。
  3. What must I do differently so that pip install matplotlib will find qt?我必须做些什么不同的事情才能让 pip install matplotlib 找到 qt?
    • This is all based on experience on Ubuntu 12.04.这都是基于 Ubuntu 12.04 的经验。
    • Installing python-qt4 globally and creating a virtualenv with --system-site-packages enabled should make matplotlib happy, even if it means littering your global environment with modules.全局安装python-qt4并创建一个启用了--system-site-packages的 virtualenv 应该会让 matplotlib 高兴,即使这意味着用模块乱扔你的全局环境。 But I haven't been able to get pip to do anything useful when trying to install PyQt4 or python-qt in a virtualenv.但是在尝试在 virtualenv 中安装 PyQt4 或 python-qt 时,我无法让 pip 做任何有用的事情。
    • Installing libqt4-dev should also alleviate any dependency issues when building anything relying on Qt4.在构建依赖于 Qt4 的任何东西时,安装libqt4-dev还应该缓解任何依赖问题。
    • If that didn't work, and others' answers here didn't help, this may shed some light on why pip is unhappy:如果这不起作用,而其他人的答案也没有帮助,这可能会说明为什么 pip 不高兴:
      • man pkg-config

        On most systems, pkg-config looks in /usr/lib/pkgconfig, /usr/share/pkgconfig, /usr/local/lib/pkgconfig and /usr/local/share/pkgconfig for these files.在大多数系统上,pkg-config 在 /usr/lib/pkgconfig、/usr/share/pkgconfig、/usr/local/lib/pkgconfig 和 /usr/local/share/pkgconfig 中查找这些文件。 It will additionally look in the colon-separated (on Windows, semicolon-separated) list of directories specified by the PKG_CONFIG_PATH environment variable.它还将查看由 PKG_CONFIG_PATH 环境变量指定的以冒号分隔(在 Windows 上,以分号分隔)的目录列表。

      • pkg-config is looking for *.pc files; pkg-config正在寻找 *.pc 文件; the fact that you found those dependencies installed somewhere doesn't mean pkg-config will find any *.pc files in those directories.您发现这些依赖项安装在某处的事实并不意味着pkg-config会在这些目录中找到任何 *.pc 文件。
      • As the man page indicates, if your packages are installed in funny places, you need to set PKG_CONFIG_PATH appropriately.正如手册页所示,如果您的软件包安装在有趣的地方,您需要适当地设置PKG_CONFIG_PATH
      • 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.如果您可能已将软件包安装到您的 virtualenv 中,那么您需要确保您的 virtualenv 的激活/停用命令适当地更新 PKG_CONFIG_PATH。 The only way I got this to work was to modify the bin/activate script in my virtualenv.我让它工作的唯一方法是修改我的 virtualenv 中的bin/activate脚本。
        • You can pretty much copy the existing code that maintains an _OLD_VIRTUAL_PATH before updating PATH upon activation, and reverting back to _OLD_VIRTUAL_PATH upon deactivation在激活时更新PATH之前,您几乎可以复制维护_OLD_VIRTUAL_PATH的现有代码,并在停用时恢复到_OLD_VIRTUAL_PATH
        • Note that the existing code isn't perfect as of the time of this post, since if your PKG_CONFIG_PATH was blank to begin with, you need a bit more logic to make sure it gets cleared upon deactivation请注意,截至本文发布时,现有代码并不完美,因为如果您的PKG_CONFIG_PATH一开始是空白的,您需要更多的逻辑来确保它在停用时被清除

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.我在使用 freetype 的其他软件包中也遇到过类似的令人沮丧的问题。 For me, the compile error came from the following:对我来说,编译错误来自以下内容:


/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!希望这会帮助任何偶然发现此问题的人!

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

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