matplotlib安装成功,使用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. 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.

出现的原因:

在Mac OS X的图像渲染后端,默认使用的是cocoa的API.这里我们需要自己设置为TkAgg.

解决方法

  • matplotlib安装成功后,会在根目录生成.matplotlib的文件夹,在终端使用cd命令进入.
$ cd .matplotlib/
  • 创建一个文件命名为:matplotlibrc,并添加内容:backend: TkAgg.
    ps.可以用vim编译器创建文件并插入内容
$ vim matplotlibrc

参考资料:stackoverflow

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容