解决UserWarning: Matplotlib is currently using agg, which is a non-GUI backend

解决方法

找到import matplotlib.pyplot as plt,在这句话前加上两句话,如下:

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

解决过程

运行run.py时,我遇到了这个bug:

UserWarning: Matplotlib is currently using agg, which is a non-GUI backend

agg是一个没有图形显示界面的终端,常用的有图形界面显示的终端有TkAgg等。如下图
取自matplotlib的_init_.py文件

于是,在vscode里,Ctrl+点击matplotlib打开其_init_.py文件,将里面的Agg全部改成TkAgg,但是运行run.py还是存在该bug。

接着参考了这篇博客讲的方法。https://blog.csdn.net/monk1992/article/details/99873776
引入一次库,执行一次print(matplotlib.get_backend()),发现每次一涉及到from tf_pose import XXX之后,输出值TkAgg就变为Agg,于是便锁定了tf_pose这个文件,但是多次寻找后还是无法找到文件里有Agg
…哭ㄒoㄒ

思来想去,我打开run.py,找到import matplotlib.pyplot as plt,在这句话上面加了两句话

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt

就可以了!

参考链接:
https://stackoverflow.com/questions/16170989/matplotlib-remove-warning-about-matplotlib-use
https://www.cnblogs.com/elitphil/p/12221345.html
https://blog.csdn.net/monk1992/article/details/99873776

猜你喜欢

转载自blog.csdn.net/qq_41073715/article/details/105033751