hans

hans

【Python】Macbook Pro MacOS Sierra 无法加载 matplotlib.pyplot 解决办法


错误提示内容:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Applications/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 114, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/Applications/anaconda/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "/Applications/anaconda/lib/python2.7/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

找到两种解决办法,第一方法我用不好使,第二个方法我用好使。

第一种方法:

cd ~./matplotlib
fc-list

老外说会运行 10 到 15 分钟,所以如果上面命令可行就耐心等一等。反正这个方法对我没用。
转自: https://github.com/matplotlib/matplotlib/issues/2919

第二种方法:

cd ~/.matplotlib 
nano matplotlibrc

添加内容:

backend : Agg

按 Shift + C,按 Y,按回车退出。

转自: https://stackoverflow.com/questions/29433824/unable-to-import-matplotlib-pyplot-as-plt-in-virtualenv

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.