• Register
0 votes
2.4k views

Problem :

I am learning Python. I have written a basic python script and trying to run the basic python script on the server:

import matplotlib.pyplot as plot
import numpy as nump

x = nump.random.randn(80)
y = nump.random.randn(80)

plot.scatter(x, y, s=30)

out_png = 'path/to/store/out_file.png'
plot.savefig(out_png, dpi=180)

I am trying to use a command python pyexample.py on this server which also has the matplotlib 1.5.1 installed on it but it fails with below error:

Traceback (most recent call last):
  File "example.py", line 7, in <module>
    plt.scatter(x, y, s=20)
  File "/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/pyplot.py", line 3241, in scatter
    ax = gca()
  File "/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/pyplot.py", line 928, in gca
    return gcf().gca(**kwargs)
  File "/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/pyplot.py", line 578, in gcf
    return figure()
  File "/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/pyplot.py", line 527, in figure
**kwargs)
  File "/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 84, in new_figure_manager
    return new_figure_manager_given_figure(num, figure)
  File "/home/USER/.virtualenvs/nnet/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 92, in new_figure_manager_given_figure
    window = Tk.Tk()
  File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 1810, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

Why am I facing above error? How can I fix it?

8 4 2
2,300 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I had faced such issue earlier. To resolve the issue I just used below code at a very beginning of your python script. So it should be able to run smoothly on the different environments.

import os
import matplotlib as matpl
if os.environ.get('DISPLAY','') == '':
    print('Currently no display found. Using the non-interactive Agg backend')
    matpl.use('Agg')
import matplotlib.pyplot as plot

 It will fix your issue for sure.

5 2 1
4,980 points

Related questions

0 votes
1 answer 42 views
42 views
Problem: Why this happened: Tkinter.tclerror: no display name and no $display environment variable
asked Mar 14 Wafa Abu Yousef 6.1k points
0 votes
1 answer 21 views
21 views
tclerror: no display name and no $display environment variable
asked Feb 16 ArifulIslam 7.5k points
1 vote
1 answer 1K views
1K views
Problem: I installed tkinter and I wrote this code to check if this works or not: import tkinter as tink a = tink.Tink() a.title('Total Seconds') button = tink.Button(a, text='Welcome', width=40, command=a.destroy) button.pack() a.mainloop() But after running this ... ", line 2, in <module> a = tink.Tink() AttributeError: module 'tkinter' has no attribute 'Tink' Can anyone help me to solve this?
asked Apr 29, 2020 samhaz 5k points
0 votes
1 answer 10 views
10 views
Problem: How to use an image for the background in tkinter?
asked Apr 19 ummesalma 29.2k points
0 votes
1 answer 14 views
14 views
Problem: how to Solve this: tkinter photoimage HELP! I need help understanding this: tkinter photoimage Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 13 Mashhoodch 13k points
0 votes
1 answer 9 views
9 views
Problem: how to Solve this: listbox in tkinter HELP! I need help understanding this: listbox in tkinter Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 13 Mashhoodch 13k points
0 votes
1 answer 11 views
11 views
Problem: how to Solve this: tkinter logo in python HELP! I need help understanding this: tkinter logo in python Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 13 Mashhoodch 13k points
0 votes
1 answer 13 views
13 views
Problem: how to Solve this: combobox in tkinter HELP! I need help understanding this: combobox in tkinter Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 13 Mashhoodch 13k points
0 votes
1 answer 11 views
11 views
Problem: how to Solve this: error: image in tkinter HELP! I need help understanding this: image in tkinter Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
asked Mar 13 Mashhoodch 13k points
0 votes
1 answer 33 views
33 views
Problem Hello Kodlogs, What is a checkbox called in tkinter? I heard it is called checkButton if yes, how does it function. Can you please explain with a code example?
asked Oct 30, 2020 hashq 1.1k points