LoginSignup
12
11

More than 5 years have passed since last update.

Ubuntu+Pyenv+Python3の環境でmatplotlibのグラフ表示ができなかった時の対処

Posted at

遭遇した現象

Ubuntu14.04上でpyenvを使ってPython3.4.2をインストールし、matplotlibをpipで導入したが、pyplotなどでshow()を実行してもグラフ表示がされなかった

原因

pyenvで3.4.2をインストールした際に、pythonからtkを利用するためのTkinterがインストールされていなかったため。python本体をインストールした後にTkinterをインストールしてもビルド時に参照されないため、先にTkinterをインストールしておく必要がある模様。

対処

もしかしたら、後でインストールしてもうまくいく方法があるのかもしれないけど、とりあえずうまく行ったのは以下。

  • いったんpyenvで3.4.2をアンインストール
$ pyenv uninstall 3.4.2
  • Ubuntuでインストールする場合のTkinterであるpython-tkをインストール
$ sudo apt-get install python-tk

(※その他のtkを利用するためのlibtkなどはインストール済み前提)

  • pyenvで3.4.2を再インストール後、matplotlibをpipで再インストール
$ pyenv install 3.4.2
$ pip install matplotlib

自分の環境では上記の対応で表示できるようになった。インストール後に適当にグラフなど作成してみて表示できればOK。

12
11
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
12
11