Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Matplotlib GDK display failed error

📅 2020-Oct-29 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ matplotlib ⬩ 📚 Archive

Problem

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

Solution

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:

export DISPLAY=:0.0

Tried with: Ubuntu 18.04


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧