解决导入matplotlib的RuntimeError: Python is not installed as a framework.

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.

解决方法:

  1. 当pip安装matplotlib后会存在目录: ~/.matplotlib
  2. 在上面的目录下新建一个文件并添加内容
    文件:~/.matplotlib/matplotlibrc
    文本内容:backend: TkAgg
  3. 保存后重新执行导入即可解决

<article style="box-sizing: inherit; outline: 0px; display: block; position: relative; padding-top: 16px; color: rgb(51, 51, 51); font-family: "SF Pro Display", Roboto, Noto, Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">

该问题在stackoverflow的页面:https://stackoverflow.com/questions/21784641/installation-issue-with-matplotlib-python

</article>

另一种是这样
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容