RuntimeError: Python is not installed as a framework 错误解决方法

在virtualenv环境下使用matplotlib绘图时遇到了这样的问题::

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 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.


解决方法如下:

  1. 打开根目录下的 .matplotlib的目录:
  2. 在这个目录下创建一个名为matplotlibrc的文件
  3. 在此文件中写入 backend: TkAgg
  4. 保存退出,重启Python交互界面或重新运行脚本,import正常执行

猜你喜欢

转载自blog.csdn.net/zyz1431/article/details/80118994