如何解决 Gdk-CRITICAL **: 17:13:03.280:gdk_cursor_new_for_display:断言"GDK_IS_DISPLAY(显示)"失败



升级到ubuntu 20.04后,我从crontab启动的python脚本中收到此错误:

Unable to init server: Could not connect: Connection refused
Unable to init server: Could not connect: Connection refused
(generate_clocks_graphs.py:4888): Gdk-CRITICAL **: 17:13:03.280: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed

有没有办法更好地理解这个错误?我找不到解决方案奇怪的是,如果我手动运行脚本,它可以完美地运行

看着代码,我意识到我没有放入以下代码行:

import matplotlib
matplotlib.use('Agg')

在输入它们之后,脚本还可以运行crontab

谢谢

Matplotlib后端依赖于一些后端来实际渲染绘图。默认后端是agg后端。此后端仅呈现PNG。Matplotlib后端的文档

#Three lines to make our compiler able to draw:
import sys
import matplotlib
matplotlib.use('Agg')
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('data.csv')
df.plot()
plt.show()
#Two  lines to make our compiler able to draw:
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()

此代码在w3schools 中执行

相关内容

  • 没有找到相关文章

最新更新