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

在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

时间: 2024-08-09 02:48:49

RuntimeError: Python is not installed as a framework 错误解决方案的相关文章

matplotlib使用时报错RuntimeError: Python is not installed as a framework

笔者在第一次安装matplotlib后运行时出现报错. 1 import matplotlib as mlb 2 from matplotlib import pylab as pl 3 4 5 x = [1,3,5,7,6,9,10,13,16] 6 y = [3,4,5,7,9,0,1,2,3] 7 8 pl.plot(x,y) 9 pl.show() 报错内容 RuntimeError: Python is not installed as a framework. The Mac OS

为python2.7安装包 RuntimeError: Python version &gt;= 3.5 required.

一台计算机上同时安装了python2.7和python3.7. 现在为python2.7安装numpy包. C:\Python27>python2 -m pip install numpy -i http://mirrors.aliyun.com/pypi/simple/Downloading/unpacking numpy  Downloading numpy-1.18.1.zip (5.4MB): 5.4MB downloaded  Running setup.py egg_info for

python学习笔记系列----(六)错误和异常

python至少有2类不同的错误:语法错误(Syntax Errors)和异常(Exceptions). 8.1 语法错误 这个单词应该还是很有必要认识的,呵呵,语法错误,也叫解析错误,是我们最不愿意发生的错误,直接拿官网的例子: >>> while True print 'Hello world' File "<stdin>", line 1, in ? while True print 'Hello world' ^ SyntaxError: inva

python manage.py shell之后的一些错误:

1. 在执行python manage.py shell之后的一些错误: [email protected]:~/myobject$ python manage.py shell /usr/lib/python2.7/dist-packages/pkg_resources.py:1049: UserWarning: /home/wyl/.python-eggs is writable by group/others and vulnerable to attack when used with

CPU/ABI显示No system images installed for this target的解决方案

CPU/ABI显示No system images installed for this target的解决方案 手动下载image http://www.androiddevtools.cn/ SDK System images 这是在创建模拟器时需要的system image,也就是在创建模拟器时 CPU/ABI项需要选择的,下载并解压后,将解压出的整个文件夹复制或者移动到 your sdk 路径/system-images文件夹下即可, 如果没有 system-images目录就先创建此文

libudev-dev : Depends: libudev0 (= 175-0ubuntu9) but 175-0ubuntu9.3 is to be installed 错误解决方案

libudev-dev : Depends: libudev0 (= 175-0ubuntu9) but 175-0ubuntu9.3 is to be installed 错误解决方案 参考文章: 1. ubuntu 12.04 libudev-dev won't install because of dependencies http://stackoverflow.com/questions/17181073/ubuntu-12-04-libudev-dev-wont-install-be

Java compiler level does not match the version of the installed Java project facet错误的解决

Javacompiler level does not match the version of the installed Java project facet错误的解决 因工作的关系,Eclipse开发的Java项目拷来拷去,有时候会报一个很奇怪的错误.明明源码一模一样,为什么项目复制到另一台机器上,就会报"java compiler level does not match the version of the installed java project facet"错误呢?

python新手常犯的17个错误

1)忘记在 if , elif , else , for , while , class ,def 声明末尾添加 :(导致 "SyntaxError :invalid syntax") 该错误将发生在类似如下代码中: 1 2 if spam== 42 print('Hello!') 2) 使用 = 而不是 ==(导致"SyntaxError: invalid syntax") = 是赋值操作符而 == 是等于比较操作.该错误发生在如下代码中: 1 2 if spam

python&quot;TypeError: &#39;NoneType&#39; object is not iterable&quot;错误解析

尊重原创博主,原文链接:https://blog.csdn.net/dataspark/article/details/9953225 [解析] 一般是函数返回值为None,并被赋给了多个变量. 实例看下: c=0def test(): if c == 1: a = b = 1 return a, b a, b = test() 使用 a, b = test()调用时,就会报错:TypeError: 'NoneType' object is not iterable 在Python判断语句中,当