LoginSignup
11
7

More than 5 years have passed since last update.

Ubuntuでmatplotlibのインストールに苦戦した記録

Last updated at Posted at 2019-01-11

自分の備忘録のために記録を残しておきます。

matplotlibをインストールしようとしたらエラーが出た

$ pip install matplotlib

...
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-khS_q5/matplotlib

pipコマンドを利用してmatplotlibをインストールしようとすると、上記のエラーが出ました。何か手立てはないものかと調べてみたら、解決法がいくつか出てきたので試してみました。
最初に紹介する方法以外が有効かどうかは検証していないのでわからないので、悪しからずです。

実行環境

VirtualBox 6.0.0
Ubuntu 16.04
python 3.6.7

libpng-devとlibfreetype6-devのインストール

こちらの内容を参考にさせて頂きました。

$ pip install matplotlib
を実行すると、

Collecting matplotlib
  Using cached https://files.pythonhosted.org/packages/eb/a0/31b6ba00bc4dcbc06f0b80d1ad6119a9cc3081ecb04a00117f6c1ca3a084/matplotlib-2.2.3.tar.gz
    Complete output from command python setup.py egg_info:
    ============================================================================
    Edit setup.cfg to change the build options

    BUILDING MATPLOTLIB
                matplotlib: yes [2.2.3]
                    python: yes [2.7.15rc1 (default, Nov 12 2018, 14:31:15)
                            [GCC 7.3.0]]
                  platform: yes [linux2]

    REQUIRED DEPENDENCIES AND EXTENSIONS
                     numpy: yes [version 1.15.4]
          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
                    macosx: no  [Mac OS-X only]
                    qt5agg: no  [PySide2 not found; PyQt5 not found]
                    qt4agg: no  [PySide not found; PyQt4 not found]
                   gtk3agg: yes [installing, version 3.30.22]
                 gtk3cairo: no  [Requires cairocffi or pycairo to be installed.]
                    gtkagg: no  [Requires pygtk]
                     tkagg: yes [installing; run-time loading from Python Tcl /
                            Tk]
                     wxagg: no  [requires wxPython]
                       gtk: no  [Requires pygtk]
                       agg: yes [installing]
                     cairo: no  [cairocffi or pycairo not found]
                 windowing: no  [Microsoft Windows only]

    OPTIONAL LATEX DEPENDENCIES
                    dvipng: no
               ghostscript: yes [version 9.26]
                     latex: no
                   pdftops: yes [version 0.62.0]

    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`

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-khS_q5/matplotlib/

という結果が出てきて、エラーが出ていることがわかります。
調べてみた結果、ビルドを実行するために「freetype」と「png」のライブラリが足りていないと怒られているそうです。

これらのライブラリをインストールするために、

$ sudo apt-get install libpng-dev
$ sudo apt-get install libfreetype6-dev

を実行しました。

実行が成功したので、再度$ pip install matplotlibを実行すると、以下のようなメッセージが出ました。

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/cycler.py'
Consider using the `--user` option or check the permissions.

パーミッション…あ…(察し)

ということで、$ sudo pip install matplotlibで再度インストールをかけると、うまくいきました。

(libpng-devとlibfreetype6-devをsudoでインストールしてしまったことが原因だと思われる?)

実行時の権限には気を付けよう!

その他やったこと

setuptoolsやuprollのインストール

こちらのサイトで紹介されている方法を一通り試してみましたが、今思えばエラーメッセージが違った気がするので大して効果はなかったような気がします。せっかちさんめ。

エラーメッセージは中途半端に読まずに最後まで読みましょう。

freetypeのインストール時に違う?ものをインストールした

なんかインストール元が違うもの(?)をインストールしてしまったので記録。
$ sudo apt-get install freetype*
今思えばこれPHP用のライブラリなのかな?:innocent:

なので、これも失敗。まったく仕方のないやつだなあ。誰かわかる人教えてほしい

結論

エラーメッセージはちゃんと読もうね!

11
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7