简体   繁体   中英

CentOS Matplotlib RuntimeError: Could not open display

I am using Cuda and run into a RuntimeError.

Environment:

Python 2.7
Cuda 9.0
Torch 0.4.0
Torchvision 0.1.8
Matplotlib 1.2.0 

error message:

File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py", line 13, in <module>
    import gtk; gdk = gtk.gdk
  File "/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 64, in <module>
    _init()
  File "/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 52, in _init
    _gtk.init_check()
RuntimeError: could not open display

Adding "MPLBACKEND=Agg" still outputs the above error message.

Anyone knows how to fix it?

I said that I would close this question. But since the answer might be interesting to some people, I leave it open. Maybe someone can explain to me why my solution worked?

I work remotely. echo $DISPLAY gives nothing. lshw -C display gives two displays. One is Nvidia's.

My problem is actually solved via adding

import matplotlib as mpl
mpl.use('Agg')

before import matplotlib.pyplot as plt .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM