Skip to content

freetype cannot be found by build #3029

Closed

Description

@kravietz

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

Activity

  1. tacaswell commented on May 1, 2014

    @tacaswell
    Member

    Can you provide any more details (distribution, version etc)?

  2. kravietz commented on May 1, 2014

    @kravietz
    Author

    Linux: Ubuntu 14.04 LTS

    Libraries:

    libfreetype6:amd64 2.5.2-1ubuntu2
    libfreetype6-dev 2.5.2-1ubuntu2

    Matplotlib matplotlib==1.3.1 (from pip)

    I've checked the setupext.py and it looks that for freetype it only checks for the ft2build.h in /usr/include and not in /usr/include/freetype2 even though it's added to list of checked directories for FreeType.

  3. tacaswell commented on May 1, 2014

    @tacaswell
    Member

    I can not reproduce this in a virtual environment on 14.04.

  4. kmike commented on May 2, 2014

    @kmike
    Contributor

    It looks similar to #2623. Even if it is not the same issue, are there plans for 1.3.2? :)

  5. espdev commented on May 7, 2014

    @espdev

    I have the same problem. I try to install matplotlib in a virtual environment on ubuntu server 14.04. freetype-devel has been installed (package libfreetype6-dev):

    esp@ubuntu-srv:~/temp$ locate freetype | grep ft2build.h
    /usr/include/freetype2/ft2build.h
    

    But matplotlib does not find it.

  6. tacaswell commented on May 7, 2014

    @tacaswell
    Member

    @espdev What version of mpl?

  7. espdev commented on May 7, 2014

    @espdev

    @tacaswell Version 1.3.1 from PyPI.

  8. razius commented on May 16, 2014

    @razius
    Contributor

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

    $ ln -s /usr/include/freetype2/ft2build.h /usr/include/
    
  9. added this to the v1.4.0 milestone on May 16, 2014
  10. steko commented on May 24, 2014

    @steko

    I found the same issue on Debian unstable with Matplotlib 1.3.1 (both from PyPI and the tag release on github - although I think they're the same).

    The fix by @razius at https://github.com/razius/matplotlib/commit/66ee42d194bef1d045918c54cc81a9cb186bd440 works for me and I managed to install matplotlib from source after applying the same patch to setupext.py

  11. benesch commented on May 28, 2014

    @benesch

    @kmike agreed, this looks like it's fixed by #2623.

    @steko @kravietz @espdev does installing from the 1.3.x branch work?

    pip install https://codeload.github.com/matplotlib/matplotlib/tar.gz/v1.3.x
    

    If so, @tacaswell I renew my request for a 1.3.2.

  12. benesch commented on May 28, 2014

    @benesch

    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.

  13. tacaswell commented on May 29, 2014

    @tacaswell
    Member

    Closing this as #3067 is merged into master.

    @benesch The issue with 1.3.2 is devs having enough time to produce one. As you can see we are swamped trying to get 1.4.0 out.

  14. post2web commented on Nov 27, 2014

    @post2web

    Same here.

    sudo apt-get install pkg-config 
    did the trick
  15. 31 remaining items

  16. janssen commented on Jun 16, 2016

    @janssen

    I'm having this problem on Windows 10, building matplotlib 1.5.1 for Python 2.7.11. I'm using the conda package manager. "conda build matplotlib" errors out with

    BUILDING MATPLOTLIB
                matplotlib: yes [1.5.1]
                    python: yes [2.7.11 |Continuum Analytics, Inc.| (default,
                            Feb 16 2016, 09:58:36) [MSC v.1500 64 bit (AMD64)]]
                  platform: yes [win32]
    
    REQUIRED DEPENDENCIES AND EXTENSIONS
                     numpy: yes [version 1.11.0]
                  dateutil: yes [using dateutil version 2.5.3]
                      pytz: yes [using pytz version 2016.4]
                    cycler: yes [using cycler version 0.10.0]
                   tornado: yes [tornado was not found. It is required for the
                            WebAgg backend. pip/easy_install may attempt to
                            install it after matplotlib.]
                 pyparsing: yes [using pyparsing version 2.1.4]
                    libagg: yes [pkg-config information for 'libagg' could not
                            be found. Using local copy.]
                  freetype: no  [The C/C++ header for freetype (ft2build.h)
                            could not be found.  You may need to install the
                            development package.]
                       png: yes [Using unknown version found on system.]
                     qhull: yes [pkg-config information for 'qhull' could not be
                            found. Using local copy.]
    
    OPTIONAL SUBPACKAGES
               sample_data: yes [installing]
                  toolkits: yes [installing]
                     tests: yes [nose 0.11.1 or later is required to run the
                            matplotlib test suite. Please install it with pip or
                            your preferred tool to run the test suite / mock is
                            required to run the matplotlib test suite. Please
                            install it with pip or your preferred tool to run
                            the test suite]
            toolkits_tests: yes [nose 0.11.1 or later is required to run the
                            matplotlib test suite. Please install it with pip or
                            your preferred tool to run the test suite / mock is
                            required to run the matplotlib test suite. Please
                            install it with pip or your preferred tool to run
                            the test suite]
    
    OPTIONAL BACKEND EXTENSIONS
                    macosx: no  [Mac OS-X only]
                    qt5agg: no  [PyQt5 not found]
                    qt4agg: no  [PySide not found; PyQt4 not found]
                   gtk3agg: no  [Requires pygobject to be installed.]
                 gtk3cairo: no  [Requires cairocffi or pycairo to be installed.]
                    gtkagg: no  [Requires pygtk]
                     tkagg: no  [The C/C++ header for Tk (tk.h) could not be
                            found.  You may need to install the development
                            package.]
                     wxagg: no  [requires wxPython]
                       gtk: no  [Requires pygtk]
                       agg: yes [installing]
                     cairo: no  [cairocffi or pycairo not found]
                 windowing: yes [installing, installing]
    
    OPTIONAL LATEX DEPENDENCIES
                    dvipng: no
               ghostscript: no
                     latex: no
                   pdftops: no
    
    OPTIONAL PACKAGE DATA
                      dlls: no  [skipping due to configuration]
    
    ============================================================================
                            * The following required packages can not be built:
                            * freetype
    

    freetype is installed. ft2build.h is present. There is no pkg-config for Windows. This seems like a real matplotlib config bug that is being covered over by punting to pkg-config. Wish it could be fixed.

  17. tacaswell commented on Jun 17, 2016

    @tacaswell
    Member

    @janssen I suggest you send this issue to the user mailing list (matplotlib-users@python.org which will require you to register to post un-moderated) or have a look at our appveyor configuration files (which build mpl in a conda env on windows).

  18. kubark42 commented on Jun 24, 2016

    @kubark42

    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.

  19. TuringZhu commented on Jul 4, 2016

    @TuringZhu

    @razius

    I run your command by root user but get an error of 'Operation not permitted' on Mac.
    And the command 'find / -name ft2build.h' get the flowing result:

    /Users/XXXX/Downloads/freetype-2.6/devel/ft2build.h
    /Users/XXXX/Downloads/freetype-2.6/include/ft2build.h
    /Users/XXXX/Downloads/matplotlib-1.5.1/src/ft2build.h
    /usr/local/apps/freetype-2.6/include/freetype2/ft2build.h
    /usr/local/include/freetype2/ft2build.h
    
  20. cfblaeb commented on Jul 19, 2016

    @cfblaeb

    Have this issue on ubuntu 16.04, python 3.5.2 (virtualenv), matplotlib 1.5.1 (installed via pip).
    ft2build.h is in /usr/include/freetype2/ft2build.h
    and sym linking it to /usr/include/ fixes it.
    $ ln -s /usr/include/freetype2/ft2build.h /usr/include/

  21. iacchus commented on Jan 5, 2017

    @iacchus
    OPTIONAL PACKAGE DATA
                      dlls: no  [skipping due to configuration]
    
    ============================================================================
                            * The following required packages can not be built:
                            * freetype
    

    Then

    sudo apt-get install libfreetype6-dev
    sudo pip install matplotlib --upgrade

    DONE

    Which, by the way, is exactly the only error that the output is clearly saying.

  22. OnlyBelter commented on Dec 25, 2017

    @OnlyBelter

    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 \
            ;
    
  23. z-pc commented on Jan 12, 2018

    @z-pc

    If you're installing matplotlib in windows.
    Then try:

    1. Modify setupext.py:
      1.1 Follow def get_base_dirs():
      1.2. "Try" replace win_bases = ['win32_static', ] -> win_bases = ['C:\Program Files\Anaconda2\Library', ]
    2. Install C++ compiler for Python at link: https://www.microsoft.com/en-us/download/details.aspx?id=44266
      If error about library, you can go to C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include
      "no replace" to C:\Users\Yourname\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\include
  24. added 2 commits that reference this issue on May 12, 2019
  25. stardigits commented on Jul 23, 2019

    @stardigits

    In termux solve by:

    pkg install freetype freetype-dev
    export CPATH=$PREFIX/include:$PREFIX/include/freetype2:$PREFIX/include/freetype2/freetype
    pip3 install matplotlib
    
  26. maximlomans commented on Dec 12, 2019

    @maximlomans

    Downloading https://files.pythonhosted.org/packages/26/04/8b381d5b166508cc258632b225adbafec49bbe69aa9a4fa1f1b461428313/matplotlib-3.0.3.tar.gz (36.6MB)
    |¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦| 36.6MB 915kB/s
    ERROR: Command errored out with exit status 1:
    command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-sp8h0mz6/matplotlib/setup.py'"'"'; file='"'"'/tmp/pip-install-sp8h0mz6/matplotlib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
    cwd: /tmp/pip-install-sp8h0mz6/matplotlib/
    Complete output (47 lines):
    ============================================================================
    Edit setup.cfg to change the build options

    BUILDING MATPLOTLIB
                matplotlib: yes [3.0.3]
                    python: yes [3.5.3 (default, Sep 27 2018, 17:25:39)  [GCC
                            6.3.0 20170516]]
                  platform: yes [linux]
    
    REQUIRED DEPENDENCIES AND EXTENSIONS
                     numpy: yes [version 1.17.2]
          install_requires: yes [handled by setuptools]
                    libagg: yes [pkg-config information for 'libagg' could not
                            be found. Using local copy.]
                  freetype: no  [The C/C++ header for freetype2 (ft2build.h)
                            could not be found.  You may need to install the
                            development package.]
                       png: no  [pkg-config information for 'libpng' could not
                            be found.]
                     qhull: yes [pkg-config information for 'libqhull' could not
                            be found. Using local copy.]
    
    OPTIONAL SUBPACKAGES
               sample_data: yes [installing]
                  toolkits: yes [installing]
                     tests: no  [skipping due to configuration]
            toolkits_tests: no  [skipping due to configuration]
    
    OPTIONAL BACKEND EXTENSIONS
                       agg: yes [installing]
                     tkagg: yes [installing; run-time loading from Python Tcl /
                            Tk]
                    macosx: no  [Mac OS-X only]
                 windowing: no  [Microsoft Windows only]
    
    OPTIONAL PACKAGE DATA
                      dlls: no  [skipping due to configuration]
    
    ============================================================================
                            * The following required packages can not be built:
                            * freetype, png
                            * Try installing freetype with `apt-get install
                            * libfreetype6-dev` and pkg-config with `apt-get
                            * install pkg-config`
                            * Try installing png with `apt-get install
                            * libpng12-dev` and pkg-config with `apt-get install
                            * pkg-config`
    ----------------------------------------
    

    ERROR: Command erred out with exit status 1: python setup.py egg_info Check the logs for full command output.

    on raspbian stretch
    sudo apt install libpng12-dev libfreetype6-dev
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    Some packages could not be installed. This may mean that you have
    requested an impossible situation or if you are using the unstable
    distribution that some required packages have not yet been created
    or been moved out of Incoming.
    The following information may help to resolve the situation:

    sudo apt install libpng12-0 libpng12-dev libpng-tools libfreetype6-dev
    sudo apt install libxslt libxml2 libxml2-dev python3-libxml2 python3-libxml2-dbg python3-lxml python3-lxml-dbg python3-testscenarios python3-jsonschema

    *not yet done yet pip3 still glitching installing pymzq & kiwisolver

  27. tacaswell commented on Dec 12, 2019

    @tacaswell
    Member

    @marxenegls Can you open a topic at https://discourse.matplotlib.org/c/community/install for installing Matplotlib on rasbian?

  28. liuqinfei commented on May 24, 2021

    @liuqinfei

    I also encountered this problem in openEuler release 20.03 (LTS-SP1).
    Package freetype-2.10.2-2.oe1.aarch64 is already installed.
    After searching, I found that the problem can be solved by performing the following operations:
    dnf install freetype-devel.aarch64 -y --nogpgcheck

  29. JakeColor commented on Jul 14, 2022

    @JakeColor

    Summarizing my experience + solution in case it helps anyone...

    I encountered this error while pip installing matplotlib from a requirements.txt in a Docker image. In particular, I requested a specific older version of matplotlib (3.4.3) while also simultaneously installing/requesting the most recent version of Python (3.10), torch, etc.

    Turns out pip will attempt to compile a packages on its own if it can't find a pre-compiled version in the public repositories. In my case, the slim Docker image didn't have the build tools necessary for pip to compile -> the freetype error.

    The solution was simple: update the version of matplotlib i was requesting to one available pre-compiled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions