【Mac】matplotlibをimportした際に「Python is not installed as a framework.」のエラー

Facebook にシェア
Pocket
LINEで送る
このエントリーを Google ブックマーク に追加

[amazonjs asin=”4873116554″ locale=”JP” title=”Pythonによるデータ分析入門 ―NumPy、pandasを使ったデータ処理”]

macでmatplotlibをインポートしようとした際に、以下の様なエラーが出た。

[shell] In [7]: import matplotlib.pyplot as plt
—————————————————————————
RuntimeError Traceback (most recent call last)
<ipython-input-7-eff513f636fd> in <module>()
—-> 1 import matplotlib.pyplot as plt

/Users/umentu/.machine_learning/lib/python3.5/site-packages/matplotlib/pyplot.py in <module>()
112
113 from matplotlib.backends import pylab_setup
–> 114 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
115
116 _IP_REGISTERED = None

/Users/umentu/.machine_learning/lib/python3.5/site-packages/matplotlib/backends/__init__.py in pylab_setup()
30 # imports. 0 means only perform absolute imports.
### MATPLOTLIBRC FORMAT
31 backend_mod = __import__(backend_name,
—> 32 globals(),locals(),[backend_name],0)
33
34 # Things we pull in from all backends

/Users/umentu/.machine_learning/lib/python3.5/site-packages/matplotlib/backends/backend_macosx.py in <module>()
22
23 import matplotlib
—> 24 from matplotlib.backends import _macosx
25
26

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
[/shell]

 

matplotlibrcの編集

pythonをインストールした環境にもよるが、以下のようにfindコマンドをかければ見つかる。
(今回は、~/.machine_learning に pyvenv で構築した。)

[shell] ~/.machine_learning/ -name matplotlibrc
/Users/umentu/.machine_learning//lib/python3.5/site-packages/matplotlib/mpl-data/matplotlibrc
[/shell] [shell] vi /Users/umentu/.machine_learning//lib/python3.5/site-packages/matplotlib/mpl-data/matplotlibrc
[/shell]

backend を macosx から backend に変更。

[shell title=”matplotlibrcの中身”] #backend : macosx
backend : TkAgg
[/shell]

これでmatplotlibが使える。

Related posts

2 Thoughts to “【Mac】matplotlibをimportした際に「Python is not installed as a framework.」のエラー”

  1. […] 【Mac】matplotlibをimportした際に「Python is not installed as a framework.」のエラー […]

  2. […] 【Mac】matplotlibをimportした際に「Python is not installed as a framework.」のエラー – from umentu import stupid […]

コメントを残す