Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

はじめに

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

環境

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

Kodaira_
python / rails ruby / 自然言語処理(NLP)をやっています
http://cl.sd.tmu.ac.jp/~kodaira/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした