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をインストールすると解決。