FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Invalid DISPLAY variable · Issue #3466 · matplotlib/matplotlib · GitHub

Repository navigation

Invalid DISPLAY variable #3466

Closed
Closed

Description

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

Activity

  1. cimarronm commented on Sep 4, 2014

    Contributor

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

  2. marcoippolito commented on Sep 4, 2014

    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?

  3. marcoippolito commented on Sep 4, 2014

    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

  4. LinZichuan commented on Mar 13, 2016

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

  5. amberkaka commented on Apr 22, 2016

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

  6. jenshnielsen commented on Apr 23, 2016

    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
  7. aluenkinglee commented on Jan 3, 2017

    @LinZichuan Great! It works

  8. bzhr commented on 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.

  9. hana9090 commented on 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

  10. hana9090 commented on 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'

  11. tacaswell commented on Apr 2, 2017

    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.

  12. teuneboon commented on Jul 24, 2017

    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.

  13. tacaswell commented on Jul 24, 2017

    Member

    @teuneboon It must be above anything that imports pyplot.

  14. 3 remaining items

  15. WeatherGod commented on Nov 17, 2017

    Member
  16. sulth commented on 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

  17. added a commit that references this issue on Mar 31, 2018
  18. XiangyunHuang commented on Apr 16, 2018

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

    That works for me in R Markdown

  19. Naman-ntc commented on May 22, 2018

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

  20. WeatherGod commented on May 22, 2018

    Member
  21. added a commit that references this issue on Jun 18, 2018
  22. kapil-varshney commented on Aug 6, 2018

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

    ^ Solved the problem for me. Thanks @jenshnielsen .

  23. added a commit that references this issue on Dec 26, 2018
  24. debovis commented on May 13, 2019

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

  25. added a commit that references this issue on Dec 23, 2020
  26. added a commit that references this issue on Apr 15, 2023
  27. added a commit that references this issue on May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL