matplotlib pip 설치 중 ft2build.h 오류

matplotlib pip 설치 중 ft2build.h 오류

2022-10-03 last update

5 minutes reading error FreeType ft2build pip Python3

matplotlib 설치 중 오류



matplotlib을 pip install 할 때 아래 오류가 발생했습니다.

error 문
Building wheels for collected packages: matplotlib
  Building wheel for matplotlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /espnet/tools/venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-x2iu72i2/matplotlib_44f82a421fe24ccca1bbcbe93d19b150/setup.py'"'"'; __file__='"'"'/tmp/pip-install-x2iu72i2/matplotlib_44f82a421fe24ccca1bbcbe93d19b150/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-m9t_thc9
       cwd: /tmp/pip-install-x2iu72i2/matplotlib_44f82a421fe24ccca1bbcbe93d19b150/
  Complete output (505 lines):

 ...............

  copying lib/matplotlib/mpl-data/stylelib/seaborn-bright.mplstyle -> build/lib.linux-x86_64-3.8/matplotlib/mpl-data/stylelib
  UPDATING build/lib.linux-x86_64-3.8/matplotlib/_version.py
  set build/lib.linux-x86_64-3.8/matplotlib/_version.py to '3.1.0'
  running build_ext
  building 'matplotlib.ft2font' extension
  creating build/temp.linux-x86_64-3.8
  creating build/temp.linux-x86_64-3.8/src
  gcc -pthread -B /espnet/tools/venv/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DFREETYPE_BUILD_TYPE=system -DPY_ARRAY_UNIQUE_SYMBOL=MPL_matplotlib_ft2font_ARRAY_API -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -D__STDC_FORMAT_MACROS=1 -Iextern/agg24-svn/include -I/espnet/tools/venv/lib/python3.8/site-packages/numpy/core/include -I/espnet/tools/venv/include/python3.8 -c src/checkdep_freetype2.c -o build/temp.linux-x86_64-3.8/src/checkdep_freetype2.o
  src/checkdep_freetype2.c:1:10: fatal error: ft2build.h: No such file or directory
   #include <ft2build.h>
            ^~~~~~~~~~~~
  compilation terminated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for matplotlib
  Running setup.py clean for matplotlib
Failed to build matplotlib

원인과 해결책



freetype이라는 글꼴에 관련된 라이브러리가 설치되어 있지 않은 것이 원인.
해결책으로는
apt install libfreetype6-dev

에서 해당 라이브러리를 설치한 후 다시 matplotlib를 설치하면 해결.