. Advertisement .
..3..
. Advertisement .
..4..
While using Python on a Linux or Unix machine, you might come across an error that seems to have a simple solution but ends up frustrating you. This error message is “_tkinter.TclError: no display name and no $DISPLAY environment variable” and it can be quite annoying. Our article will give tips and tricks to solve this error.
How To Fix The Error “_tkinter.TclError: no display name and no $DISPLAY environment variable”
You have matplotlib 1.5.1 installed on your system and are attempting to use it in your code, but you may encounter the following error.
_tkinter.TclError: no display name and no $DISPLAY environment variable
To fix this problem, set matplotlib never to utilize the Xwindows backend. This error can be fixed by applying the following two lines to the top of your .py file: import matplotlib matplotlib.use(‘Agg’). The Agg backend must be used, and your problem should be resolved.
Option 1: At the top of your.py file, include these two lines
Set matplotlib never to utilize the Xwindows backend. This error can be fixed by applying the following two lines to the top of your .py file:
import matplotlib
matplotlib.use(‘Agg’)
Option 2: Simply utilize the ‘Agg’ backend
The Agg backend must be used. It’s similar to this.
import os import matplotlib as mpl if os.environ.get('DISPLAY','') == '': print('no display found. Using non-interactive Agg backend') mpl.use('Agg') import matplotlib.pyplot as plt
Now, your problem should be resolved.
Conclusion
We hope you found our blog post on how to fix the problem “_tkinter.TclError: no display name and no $DISPLAY environment variable” useful. If you have any other questions or concerns about this issue, please leave a comment. Thank you for taking the time to read; we are always thrilled when one of our posts can provide useful knowledge on this subject!
Leave a comment