Hello Guys, How are you all? Hope You all Are Fine. Today I am using matplotlib 1.5.1 in my system and I am trying to use it in my code but I am facing following error _tkinter.TclError: no display name and no $DISPLAY environment variable in python. So Here I am Explain to you all the possible solutions here.
Without wasting your time, Let’s start This Article to Solve This Error.
How _tkinter.TclError: no display name and no $DISPLAY environment variable Error Occurs ?
I am using matplotlib 1.5.1 in my system and I am trying to use it in my code but I am facing following error.
_tkinter.TclError: no display name and no $DISPLAY environment variable
How To Solve _tkinter.TclError: no display name and no $DISPLAY environment variable Error ?
How To Solve _tkinter.TclError: no display name and no $DISPLAY environment variable Error ?
To Solve _tkinter.TclError: no display name and no $DISPLAY environment variable Error Here Probably You need to set matplotlib to not use the Xwindows backend. This error is solved by adding these two lines in the at the top of your .py file: import matplotlib matplotlib.use(‘Agg’). You need to use the Agg backend And your error must be solved.
_tkinter.TclError: no display name and no $DISPLAY environment variable
To Solve _tkinter.TclError: no display name and no $DISPLAY environment variable Error Here Probably You need to set matplotlib to not use the Xwindows backend. This error is solved by adding these two lines in the at the top of your .py file: import matplotlib matplotlib.use(‘Agg’). You need to use the Agg backend And your error must be solved.
Solution 1: add these two lines in the at the top of your .py file
Here Probably You need to set matplotlib to not use the Xwindows backend. This error is solved by adding these two lines in the at the top of your .py file.
import matplotlib
matplotlib.use('Agg')
Solution 2: Just use the 'Agg'
backend
You need to use the Agg backend. Just like 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
And your error must be solved.
Summary
It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?
Also, Read