freetype cannot be found by build

I’ve tried to install matplotlib using pip on Linux and it couldn’t find freetype during the build process, even though it’s installed with dev packages.

freetype: no  [The C/C++ header for freetype2 (ft2build.h)
                    could not be found.  You may need to install the
                    development package.]

But:

$ ls -l /usr/include/freetype2/ft2build.h 
-rw-r--r-- 1 root root 2383 Mar 13 17:29 /usr/include/freetype2/ft2build.h

And:

$ freetype-config --cflags
-I/usr/include/freetype2

Author: Fantashit

7 thoughts on “freetype cannot be found by build

  1. A temporary fix would be to create a symlink before installing matplotlib using pip.

    $ ln -s /usr/include/freetype2/ft2build.h /usr/include/
    
  2. Never mind; upon further investigation, this is unrelated to #2623.

    This bug only occurs if pkg-config is not installed; a simple

    sudo apt-get install pkg-config

    will shore up the include paths for now.

  3. @calebebrim Did you actually install freetype?

    brew install freetype
    

    Freetype is a dependency of matplotlib and needs to be installed for matplotlib to build. pkg-config only helps locate it.

  4. Same problem here, sudo apt-get install pkg-config resolved it. It would be very helpful if the build script would either suggest checking pkg-config directly, or would point to this GitHub issue. It would certainly have saved me at least 15 minutes of trial and error before landing here.

  5. If you are using docker, and install matplotlib in python:3.5-alpine, add this in your Dockerfile may hlep:

    RUN set -e; \
            apk add --no-cache --virtual .build-deps \
                    gcc \
                    libc-dev \
                    linux-headers \
                    mariadb-dev \
                    python3-dev \
                    postgresql-dev \
                    freetype-dev \
                    libpng-dev \
                    libxml2-dev \
                    libxslt-dev \
                    zlib-dev \
            ;
    

Comments are closed.