kjo
kjo

Reputation: 35311

pip install matplotlib: "no pkg-config"

When I run pip install matplotlib (within a virtualenv), the first lines of output are:

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
  2. the missing Qt library.

First, contrary to what the output above says, pkg-config is in fact installed and on the 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:

% 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)?
  2. What must I do differently so that pip install matplotlib will find pkg-config?
  3. What must I do differently so that pip install matplotlib will find qt?

Upvotes: 15

Views: 44876

Answers (6)

zhaoqing
zhaoqing

Reputation: 795

On Mac OS: I use which pkg-config to check installation. If not, use brew to install and it works:

brew install pkg-config

Upvotes: 15

Grzegorz Pawełczuk
Grzegorz Pawełczuk

Reputation: 385

sudo apt-get build-dep python-matplotlib

Upvotes: 11

jasterm007
jasterm007

Reputation: 173

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.

So to answer the original questions:

  1. 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.
  2. What must I do differently so that pip install matplotlib will find pkg-config?
    • I'm fairly certain it's finding pkg-config just fine; it's just not detecting any useful information for freetype2 and libpng.
  3. 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-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. 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-dev should 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-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. 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 is looking for *.pc files; the fact that you found those dependencies installed somewhere doesn't mean pkg-config will 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_PATH appropriately.
      • 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/activate script in my virtualenv.
        • 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
        • 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

Upvotes: 1

Arun Jayapal
Arun Jayapal

Reputation: 457

Just install freetype fonts to get 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.

Upvotes: 8

John Haberstroh
John Haberstroh

Reputation: 485

I had an almost identical error. I looked through the errors further down, and it seems like the problem was with freetype2.

I've had similarly frustrating issues with other packages that use freetype. For me, the compile error came from the following:


/usr/local/include/freetype2/freetype/*.h are the freetype files.

/usr/local/include is the search directory.

-Ifreetype/*.h is the flag passed to the compiler.


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.

Hopefully this will help anyone who stumbles across this!

Upvotes: 0

Leo Mizuhara
Leo Mizuhara

Reputation: 375

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

I got this set of commands to set up 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.

Upvotes: 2

Related Questions