code: def fix_display(self):
          
  
          try:
              tkinter.Tk()
          except (tkinter.TclError, NameError): # If there is no display.
              try:
                  import matplotlib as mpl
              except ImportError:
                  pass
              else:
                  print("Setting matplotlib backend to Agg")
                  mpl.use('Agg')
docs: If this is being run on a headless system the Matplotlib
          backend must be changed to one that doesn't need a display.