[英]Matplotlib cannot switch backend to 'TkAgg', as 'qt' is currently running
I am trying to display a plot in Pycharm Comunity Edition and I get the following error:我试图在 Pycharm 社区版中显示 plot 并且我收到以下错误:
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so >cannot show the figure.
UserWarning: Matplotlib 目前正在使用 agg,这是一个非 GUI 后端,所以 > 无法显示该图。
I have installed and imported tkinter
before importing matplotlib
but I cannot make Matplotlib switch to 'TKAgg'.在导入
tkinter
之前,我已经安装并导入了matplotlib
,但我无法将 Matplotlib 切换到“TKAgg”。
I tried running我试着跑步
matplotlib.use('TKAgg', force=True)
and和
plt.switch_backend('tkagg')
and they both result in the following error:并且它们都导致以下错误:
ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive >framework, as 'qt' is currently running
ImportError:无法加载后端“TkAgg”,它需要“tk”交互式>框架,因为“qt”当前正在运行
I also tried adding MPLBACKEND=TkAgg to the environment variables but did not change anything.我还尝试将 MPLBACKEND=TkAgg 添加到环境变量中,但没有改变任何东西。
Does anyone have an idea what else I can do to solve this so that I can display graphs?有谁知道我还能做些什么来解决这个问题,以便我可以显示图表?
I had the same issue, and I somehow got it to work by putting the matplotlib.use("TkAgg") statement at the end of my module imports.我遇到了同样的问题,我通过将 matplotlib.use("TkAgg") 语句放在模块导入的末尾以某种方式让它工作。
Essentially, the call to TkAgg was the last thing prior to the code.本质上,对 TkAgg 的调用是代码之前的最后一件事。 Not sure how it worked, but it worked for me.
不知道它是如何工作的,但它对我有用。 I think another module I was originally importing after the TkAgg statement was the issue.
我认为在 TkAgg 语句之后我最初导入的另一个模块是问题所在。
I have tried putting the TkAgg statement back early in the module imports, and the issue comes back.我尝试将 TkAgg 语句放回模块导入的早期,问题又回来了。 When it is the last thing listed before my code starts, it works fine.
当它是我的代码开始之前列出的最后一件事时,它工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.