Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error only when submitting python job in Slurm

Tags:

python

slurm

I am running a python script on a remote machine, which runs fine, but soon after starting I get the warning:

QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-myusername'

I didn't worry about this warning as it wasn't stopping my code.

I then tried to submit the same code using Slurm workload manager, using the command:

sbatch --wrap="python mycode.py" -N 1 --cpus-per-task=8 -o mycode.o

When I do this, the code doesn't work, and I get the following error:

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"

Obvious the error is something to do with a figure I am producing. I'm not sure if it is related to the XDG_RUNTIME_DIR warning.

Any help would be appreciated.

like image 289
user1551817 Avatar asked Jul 15 '19 16:07

user1551817


1 Answers

I think your problem is related to below thread

tkinter.TclError: couldn't connect to display "localhost:18.0"

Solution to change your import like below

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

Few more threads

Pyplot "cannot connect to X server localhost:10.0" despite ioff() and matplotlib.use('Agg')

like image 73
Tarun Lalwani Avatar answered Nov 03 '22 08:11

Tarun Lalwani