I had a Python script to generate a plot and write it to an image file using Matplotlib. But the matplotlib import line in the script started failing on a certain computer with this error:
>>> import matplotlib.pyplot as pyplot Unable to init server: Could not connect: Connection refused Unable to init server: Could not connect: Connection refused (my_plotter.py:13763): Gdk-CRITICAL **: 13:58:24.057: gdk_cursor_new_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
It seemed like GDK was being used to render the plot and it was requiring a correct X display configuration for some reason.
On a hunch, I checked the
DISPLAY of my shell and it was not set. So I set it to the default value and this fixed the above error:
Tried with: Ubuntu 18.04