pip install matplotlib: "no pkg-config"

30,711

Solution 1

sudo apt-get build-dep python-matplotlib

Solution 2

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

brew install pkg-config

Solution 3

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.

Solution 4

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.

Solution 5

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
Share:
30,711
kjo
Author by

kjo

Updated on July 05, 2022

Comments

  • kjo
    kjo almost 2 years

    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?