简体   繁体   English

Matplotlib 无法将后端切换到“TkAgg”,因为“qt”当前正在运行

[英]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.

相关问题 Google Colab:ImportError:无法加载后端“TkAgg”,它需要“tk”交互式框架,因为“无头”当前正在运行 - Google Colab: ImportError: Cannot load backend 'TkAgg' Which requires the 'tk' interactive framework, as 'headless' is currently running ImportError:无法加载需要“tk”交互式框架的后端“TkAgg”,因为“无头”当前正在运行 - ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running Matplotlib tkagg后端性能 - Matplotlib tkagg backend performance 在4K屏幕上使用Matplotlib和TKAgg或Qt5Agg后端 - Using Matplotlib with TKAgg or Qt5Agg backend on 4K screen Matplotlib 不适用于 Linux。 无法加载后端“TkAgg” - Matplotlib not working for LInux. Cannot load backend 'TkAgg' Matplotlib backend_tkagg TclError - Matplotlib backend_tkagg TclError matplotlib:使用TkAgg后端减小图形大小时遇到​​麻烦 - matplotlib: trouble reducing figure size with TkAgg backend VSCode 无法切换 matplotlib 后端:ImportError: Cannot load backend 'Qt5Agg' which requires the 'qt5' interactive framework - VSCode cannot switch matplotlib backend: ImportError: Cannot load backend 'Qt5Agg' which requires the 'qt5' interactive framework 无法加载需要“qt5”交互框架的后端“Qt5Agg”,因为“headless”当前正在运行 - Cannot load backend 'Qt5Agg' which requires the 'qt5' interactive framework, as 'headless' is currently running 如何在 Jupyter 中使用 matplotlib 后端“TkAgg” - How to use matplotlib backend "TkAgg" in Jupyter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM