from matplotlib import pyplot 报错处理

在Mac上的第二个Python环境上装matplotlib后,测试以下代码:

from matplotlib import pyplot   // 导入库
pyplot.plot([1,2,3,4], [1,4,9,16])  // 绘图
pyplot.show()       // 图显示

但是输入第一行后发现报错:

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

解决的方法也很简单:

vim ~/.matplotlib/matplotlibrc 

然后输入以下内容:

backend: TkAgg

你可能感兴趣的:(L_Python)