本文介绍了matplotlib:RuntimeError:Python未作为框架安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题曾在此处(也是.但是,该解决方案无法解决我的问题.

This question has been asked before, in here, also here. However, the solution didn't fix the problem for my case.

最初的错误是,当我尝试import matplotlib.pyplot时,我得到了:

The original error is, when I try to import matplotlib.pyplot, I got:

我按照解决方案添加了一个代码为backend: TkAgg~/.matplotlib/matplotlibrc文件.完成此操作后,我的错误更改为:

I followed the solutions to add a ~/.matplotlib/matplotlibrc file with the code: backend: TkAgg. After doing that, my error changed to:

我不知道该如何解决.我没有使用虚拟机.你可以帮帮我吗?谢谢!

I have no idea how to fix that. I'm not using a virtual machine. Could you help me? Thank you!

PS:我发现是通过添加:

PS: I found out that by adding:

import matplotlib.pyplot之前,它似乎起作用.但是每次都添加这两行代码很烦人.有人知道发生了什么,如何解决?谢谢!

before import matplotlib.pyplot, it seems to work. But adding those two lines of codes every time is annoying... Does anyone know what's going on and how I can fix it? Thank you!

推荐答案

我在virtualenv中运行脚本. Python版本是3.5.

I run my script in virtualenv. Python version is 3.5.

添加一行:

backend: TkAgg

在文件中:

~/.matplotlib/matplotlibrc

这解决了问题.

如果您想进一步了解为什么添加此功能可以解决此问题,则可以阅读自定义matplotlib的后端.而 TkAgg 解决了此问题,因为它与Tkinter具有依赖性.

If you want to know more about why adding this solves the problem, you can read about customizing matplotlib's backend. And TkAgg solves this issue because of it's dependency with Tkinter.

这篇关于matplotlib:RuntimeError:Python未作为框架安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:13