我正在远程计算机上运行python脚本,该脚本运行正常,但是启动后不久,我得到警告:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-myusername'
我并不担心这个警告,因为它没有停止我的代码。
然后我尝试使用Slurm工作负载管理器通过以下命令提交相同的代码:
sbatch --wrap="python mycode.py" -N 1 --cpus-per-task=8 -o mycode.o
执行此操作时,代码不起作用,并且出现以下错误:
Traceback (most recent call last):
File "mycode.py", line 99, in <module>
fig=plt.figure(figsize=(20, 12), dpi = 100, facecolor='w', edgecolor='k')
File "/home/myusername/miniconda3/lib/python3.7/site-packages/matplotlib/pyplot.py", line 539, in figure
**kwargs)
File "/home/myusername/miniconda3/lib/python3.7/site-packages/matplotlib/backend_bases.py", line 3252, in new_figure_manager
return cls.new_figure_manager_given_figure(num, fig)
File "/home/myusername/miniconda3/lib/python3.7/site-packages/matplotlib/backends/_backend_tk.py", line 946, in new_figure_manager_given_figure
window = tk.Tk(className="matplotlib")
File "/home/myusername/miniconda3/lib/python3.7/tkinter/__init__.py", line 2023, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)_tkinter.TclError: couldn't connect to display "localhost:36.0"
很明显,该错误与我生成的图形有关。我不确定它是否与XDG_RUNTIME_DIR警告有关。
任何帮助将不胜感激。
答案 0 :(得分:3)
我认为您的问题与以下线程有关
tkinter.TclError: couldn't connect to display "localhost:18.0"
解决方案,如下所示更改导入
import matplotlib
matplotlib.use('pdf')
import matplotlib.pyplot as plt
更多线程
Pyplot "cannot connect to X server localhost:10.0" despite ioff() and matplotlib.use('Agg')