プログラミングとかLinuxとかの備忘録

プログラミング、Linuxでハマった箇所や環境構築のメモ

virtualenvにmatplotlibをインストールする

スポンサーリンク

matplotlibをvirtualenvにインストールした際の備忘録

実行環境は
* CentOS7
* Python2.7.10 (Python2.7.10をソースからインストールする)

仮想環境作成

$ mkvirtualenv --python /opt/python2.7.10/bin/python2.7 --no-site-packages plot
$ workon plot

numpyのインストール

(plot)$ pip install numpy
Successfully installed numpy-1.9.3

matplotlibのインストール

必要なライブラリをインストール

$ sudo yum -y install agg tk-devel
$ sudo yum -y install libpng-devel

matplotlibのインストール

(plot)$ pip install matplotlib
Successfully installed cycler-0.9.0 matplotlib-1.5.0 pyparsing-2.0.5 python-dateutil-2.4.2 pytz-2015.7 six-1.10.0

show()しても何も表示されない

matplotlibrcの場所を確認する

$ workon plot

(plot)$ python
>>> import matplotlib
>>> matplotlib.matplotlib_fname()
u'${PYENV}/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc'
>>> quit()

matplotlib(36行目)のbackendを書き換える

$ vi matplotlibrc
backend      : tkagg

これでも動かなければmatplotlibを再インストールする

(plot)$ pip uninstall matplotlib
(plot)$ pip --no-cache-dir install matplotlib