RuntimeError: Python is not installed as a framework

Mac自帶的python編輯器是2.7,下載了一個3.6的之後,在virtualenv中運行py文件,文件中 import 了 matplotlib 出現以下錯誤:

Traceback (most recent call last):
  File "3_1.py", line 4, in <module>
    import matplotlib.pyplot as plt
  File "/Users/wfc/PycharmProjects/env3.6/lib/python3.6/site-packages/matplotlib/pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/Users/wfc/PycharmProjects/env3.6/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "/Users/wfc/PycharmProjects/env3.6/lib/python3.6/site-packages/matplotlib/backends/backend_macosx.py", line 17, 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 using (Ana)Conda please install python.app and replace the use of 'python' with 'pythonw'. See 'Working with Matplotlib on OSX' in the Matplotlib FAQ for more information.

似乎是因爲虛擬環境與默認環境的安裝配置不同造成的。

解決方法:

這個時候在“~”路徑下面 (cd  ~),使用命令ls  -a會列出所有的文件,包括隱藏文件,會發現有一個.matplotlib的隱藏文件,然後在~/.matplotlib該目錄下面新建一個名爲matplotlibrc( vi  matplotlibrc)的文件,在該文件裏面裏面編輯內容backend: TkAgg,保存(esc) 退出(:wq)即可


發佈了49 篇原創文章 · 獲贊 14 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章