165
114

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pyenvとvirtualenvで環境構築した時にmatplotlib.pyplotが使えなかった時の対処法

Last updated at Posted at 2016-04-19

#はじめに
こういった問題は環境によって対処できない場合があるので,あくまで一例だと思ってください.

#環境
MacOSX Yosemite

#pyenvとvirtualenv
仮想環境を構築する便利なものです.
使い方等は過去記事参照:pyenvとvirtualenvで環境構築

#エラー

$ pyenv install 3.5.1
$ pyenv virtualenv 3.5.1 mpl35
$ pyenv activate mlp35
$ pip install matplotlib numpy scipy
$ python -c "import matplotlib.pyplot"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/kodairatomonori/.pyenv/versions/mpl35/lib/python3.5/site-packages/matplotlib/pyplot.py", line 114, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/Users/kodairatomonori/.pyenv/versions/mpl35/lib/python3.5/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/Users/kodairatomonori/.pyenv/versions/mpl35/lib/python3.5/site-packages/matplotlib/backends/backend_macosx.py", line 24, in <module>
    from matplotlib.backends import _macosx
RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ

こんな感じでエラーがでてしまう...

#解決できた方法
virtualenv環境でPILとmatplotlibをインストールしようとしたら盛大にドハマりした件

これみると,backendってところを変更すればいいはず

matplotlibrcの38行目の
backend : macosx
これを
backend : Tkagg
と変更させると解決できた!

matplotlibrcの場所は,

$python -c "import matplotlib;print(matplotlib.matplotlib_fname())"

で確認できます.

#探した際に見たサイト
最終的にはこのサイトを見て解決:virtualenv環境でPILとmatplotlibをインストールしようとしたら盛大にドハマりした件

matplotlib公式:Working with Matplotlib in Virtual environments
matplotlib公式:Customizing matplotlib
pyenv-virtualenvのissuespyenv virtualenv not work for matplotlib #140

165
114
2

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
165
114

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?