在我的ubuntu 18.04 VM中,使用Python 3.7.7和matplotlib 3.3.1,这段代码可以正常工作:
plt.rcParams['toolbar'] = 'toolmanager'
fig = plt.figure()
tm = fig.canvas.manager.toolmanager
tm.remove_tool('help') # Fails here in ubuntu in Azure!
但是,当从我的Azure DevOps构建管道中的单元测试调用相同的代码时,它在
tm.remove_tool('help')
上
ubuntu-18.04
Microsoft托管的VM具有:
File "/opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/site-packages/matplotlib/backend_managers.py", line 228, in remove_tool
tool.destroy()
AttributeError: 'NoneType' object has no attribute 'destroy'
这在Python 3.6.12和3.7.9中都会发生
ubuntu-18.04
Azure虚拟机。两者都使用matplotlib 3.3.1。
但是,相同的代码在Windows上运行时没有错误
windows-2019
微软在Python 3.6.8和3.7.9中托管了VM,也在matplotlib 3.3.1上托管了VM。
有没有其他人看到了这一点,并得到了解决方案或变通方法?不幸的是,我无法在我自己的ubuntu VM上复制它。
也许微软主持
ubuntu-18.04
VM缺少matplotlib需要的东西?或者有一个奇怪的matplotlib bug?当我使用matplotlib 3.1.1时,我在Azure中没有看到这个问题。
2020年9月2日更新
添加行后
print("Tools: %s" % tm._tools)
初始化后
tm
我发现
tm._tools
是Azure中Windows上有许多条目的字典(和
tm._tools['help']
是a
matplotlib.backends._backend_tk.HelpTk
对象)。但在Azure上的Linux中
tm._tools
是一个空字典:
{}
!
那么,我需要在Linux中为matplotlib做额外的事情吗?Azure使用的18.04 ubuntu VM上的软件包如下
here
如果有帮助,请包括以下内容:
2021年8月5日更新
运行此程序可以修复我自己的ubuntu VM中的问题:
$ sudo apt-get install python3-tk
我认为它安装了Tcl/Tk的后端库(参见
here
). 但不幸的是,此修复程序无法解决
ubuntu-18.04
Azure虚拟机。