Skip to content

Invalid DISPLAY variable #3466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
marcoippolito opened this issue Sep 4, 2014 · 23 comments
Closed

Invalid DISPLAY variable #3466

marcoippolito opened this issue Sep 4, 2014 · 23 comments

Comments

@marcoippolito
Copy link

In my AWS Ubuntu 14.02 instance I installed the matplotlib dependencies and then via pip I installed matplotlib:

sudo apt-get build-dep python-matplotlib

sudo pip install matplotlib

sudo pip freeze:
matplotlib==1.4.0

in a brand new file plotting1.py I wrote:

!/usr/bin/python

from pylab import *
plot([1,2,3])
show()

after typying chmod +x plotting1.py, I executed the little script:

time python plotting1.py
Traceback (most recent call last):
File "plotting1.py", line 4, in
plot([1,2,3])
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 3086, in plot
ax = gca()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 827, in gca
ax = gcf().gca(*_kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 461, in gcf
return figure()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 434, in figure
*_kwargs)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4ag g.py", line 47, in new_figure_manager
return new_figure_manager_given_figure(num, thisFig)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4ag g.py", line 54, in new_figure_manager_given_figure
canvas = FigureCanvasQTAgg(figure)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4ag g.py", line 72, in init
FigureCanvasQT.init(self, figure)
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt4.p y", line 68, in init
_create_qApp()
File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_qt5.p y", line 139, in _create_qApp
raise RuntimeError('Invalid DISPLAY variable')
RuntimeError: Invalid DISPLAY variable

real 0m0.404s
user 0m0.284s

What do I have to do now?

Looking forward to your kind help.
Kind regards.
Marco

@cimarronm
Copy link
Contributor

Do you have the X server running? What is your DISPLAY environment variable set to (echo $DISPLAY)?

@marcoippolito
Copy link
Author

Hi,
thanks for helping!!!!

echo $DISPLAY

so it say nothing

What do I have to do to make X server running in my AWS Ubuntu 12.04 instance?
I rebooted but still nothing:
echo $DISPLAY

Do you know how to set the DISPLAY environment variable to disp?

@marcoippolito
Copy link
Author

Solved. I cannot visualize graphs on AWS server.
so I have to save them in files and download them locally.

Thanks for your kind help.
Kind regards.
Marco

@LinZichuan
Copy link

I had the same problem and I solved it by adding plt.switch_backend('agg') after import matplotlib.pyplot as plt

@amberkaka
Copy link

@LinZichuan I encoutered this problem too and your solution works. Thanks for your sharing!

@jenshnielsen
Copy link
Member

For the record it's better to chose a backend before importing pyplot i.e.

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt

@aluenkinglee
Copy link

@LinZichuan Great! It works

@bzhr
Copy link

bzhr commented Jan 5, 2017

For me on AWS ec2 instance

import matplotlib matplotlib.use('agg')
Does not work. But
plt.switch_backend('agg')
does the trick.

@hana9090
Copy link

hana9090 commented Apr 1, 2017

@jenshnielsen
I have this error, although I add

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt

Demo for data/demo/000456.jpg
Detection took 0.233s for 300 object proposals
Traceback (most recent call last):
File "./tools/demo.py", line 153, in
demo(net, im_name)
File "./tools/demo.py", line 102, in demo
vis_detections(im, cls, dets, thresh=CONF_THRESH)
File "./tools/demo.py", line 51, in vis_detections
fig, ax = plt.subplots(figsize=(12, 12))
File "/home/usr/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 1177, in subplots
fig = figure(**fig_kw)
File "/home/usr/anaconda2/lib/python2.7/site-packages/matplotlib/pyplot.py", line 527, in figure
**kwargs)
File "/home/usr/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py", line 46, in new_figure_manager
return new_figure_manager_given_figure(num, thisFig)
File "/home/usr/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py", line 53, in new_figure_manager_given_figure
canvas = FigureCanvasQTAgg(figure)
File "/home/usr/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py", line 76, in init
FigureCanvasQT.init(self, figure)
File "/home/usr/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_qt4.py", line 68, in init
_create_qApp()
File "/home/usr/anaconda2/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.py", line 138, in _create_qApp
raise RuntimeError('Invalid DISPLAY variable')
RuntimeError: Invalid DISPLAY variable

@hana9090
Copy link

hana9090 commented Apr 1, 2017

@bzhr

I have modified as you suggested, by replacing plt with plt.switch_backend('agg')
I have the following error:

Demo for data/demo/000456.jpg
Detection took 0.268s for 300 object proposals
Traceback (most recent call last):
File "./tools/demo2.py", line 153, in
demo(net, im_name)
File "./tools/demo2.py", line 102, in demo
vis_detections(im, cls, dets, thresh=CONF_THRESH)
File "./tools/demo2.py", line 51, in vis_detections
fig, ax = plt.switch_backend('agg').subplots(figsize=(12, 12))
AttributeError: 'NoneType' object has no attribute 'subplots'

@tacaswell
Copy link
Member

@hana9090 That is not how the library works. plt.switch_backend() changes some global state which affects how future calls to plt.subplots() works.

@teuneboon
Copy link

For others having this issue: for me it was solved by putting the

import matplotlib
matplotlib.use('agg')

all the way at the top of the file it was used in. Initially I though "hmm, it should be fine as long as I put it above all other matplotlib stuff", but nope! It had to be all the way on the top for it to work.

@tacaswell
Copy link
Member

@teuneboon It must be above anything that imports pyplot.

idiapbbb pushed a commit to bioidiap/bob.bio.base that referenced this issue Sep 8, 2017
@HappyStorm
Copy link

@LinZichuan Thanks for sharing!!! It works for me 😆 !

@empty16
Copy link

empty16 commented Nov 16, 2017

@LinZichuan I encountered this problem too and it works for me, Thanks for sharing! Mark!

@sulth
Copy link

sulth commented Nov 17, 2017

@tacaswell Iam also having the same problem of visualizing the output using plt.show() ,when used plt.switch_backend().How to solve this issue.

@WeatherGod
Copy link
Member

WeatherGod commented Nov 17, 2017 via email

@sulth
Copy link

sulth commented Nov 18, 2017

Hi Thanks !i got it.it was due to agg (non interactive visualisation env).replaced it with qt4agg (interactive)and it worked

wkentaro added a commit to wkentaro/labelme that referenced this issue Mar 31, 2018
@XiangyunHuang
Copy link

import matplotlib.pyplot as plt
plt.switch_backend('agg') # Very Important in R Markdown

That works for me in R Markdown

@Naman-ntc
Copy link

Is there any other method where matplotlib plots and shows over ssh or manually saving is the only option??

@WeatherGod
Copy link
Member

WeatherGod commented May 22, 2018 via email

linzhiqiu added a commit to linzhiqiu/tensorboard-pytorch that referenced this issue Jun 18, 2018
This demo doesn't work on my Linux machine because it doesn't declare a backend for matplotlib. With this change it can now work on my server. This seems to be a common issue as described here: matplotlib/matplotlib#3466
lanpa pushed a commit to lanpa/tensorboardX that referenced this issue Jun 19, 2018
This demo doesn't work on my Linux machine because it doesn't declare a backend for matplotlib. With this change it can now work on my server. This seems to be a common issue as described here: matplotlib/matplotlib#3466
@kapil-varshney
Copy link

import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt

^ Solved the problem for me. Thanks @jenshnielsen .

@debovis
Copy link

debovis commented May 13, 2019

Switching to 'agg' does solve the issue. Although I am back stuck at this issue: #12074

joaks1 added a commit to phyletica/pycoevolity that referenced this issue Nov 8, 2019
Explicitly specifying matplotlib backend, which according to this
issue on GitHub:

matplotlib/matplotlib#3466

should fix the problem with the DISPLAY env variable being invalid on
some systems.
codebaragi23 pushed a commit to codebaragi23/mindAT that referenced this issue Dec 23, 2020
0ssamaak0 pushed a commit to 0ssamaak0/DLTA-AI that referenced this issue Apr 15, 2023
0ssamaak0 pushed a commit to 0ssamaak0/DLTA-AI that referenced this issue May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests