博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
RuntimeError: Python is not installed as a framework 错误解决方案
阅读量:4580 次
发布时间:2019-06-09

本文共 1190 字,大约阅读时间需要 3 分钟。

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

>>> import matplotlib.pyplot as plt

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
...
in <module>
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 Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ

 

似乎是因为虚拟环境与默认环境的安装配置不同造成的。

搜索错误信息之后,在STO上找到了解决方案:

 

1、pip安装matplotlib之后,会在根目录下产生一个.matplotlib的目录:

➜ bin ll ~/.matplotlib

total 280
-rw-r--r-- 1 me staff 78K 10 4 2015 fontList.cache
-rw-r--r-- 1 me staff 59K 1 17 15:56 fontList.py3k.cache
drwxr-xr-x 2 me staff 68B 10 4 2015 tex.cache

 

2、在这个目录下创建一个名为matplotlibrc的文件,内容是:

backend: TkAgg

然后保存退出,重启Python交互界面或重新运行脚本,import正常执行。

 

STO答案地址:http://stackoverflow.com/questions/21784641/installation-issue-with-matplotlib-python

 

转载于:https://www.cnblogs.com/harelion/p/5637767.html

你可能感兴趣的文章