import matplotlib.pyplot as plt
报错:
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.
解决方法:
当pip安装matplotlib后会存在目录: ~/.matplotlib
在上面的目录下新建一个文件并添加内容
文件:~/.matplotlib/matplotlibrc
文本内容:backend: TkAgg
保存后重新执行导入即可解决
另一种是这样
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt