【已解决】mac使用matplotlib报错:RuntimeError: Python is not installed as a framework.

mac使用matplotlib报错:RuntimeError: Python is not installed as a framework.

问题描述:

在macos上使用import matplotlib.pyplot时候遇到报错:

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

解决方法:

  1. 在~/.matplotlib/matplotlibrc文件中添加一行:backend: TkAgg
echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc
  1. 在import matplotlib.pyplot前添加:
import matplotlib
matplotlib.use('TkAgg')

版权声明:本文为CCCDeric原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。