码迷,mamicode.com
首页 > 编程语言 > 详细

linux 使用 Python 画图工具matplotlib 提示display 错误

时间:2019-12-22 12:52:23      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:could   last   错误   canvas   run   port   error:   back   ken   

import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 97, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
    globals(),locals(),[backend_name])
  File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in <module>
    from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,  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

使用一下命令

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

成功画图

linux 使用 Python 画图工具matplotlib 提示display 错误

标签:could   last   错误   canvas   run   port   error:   back   ken   

原文地址:https://www.cnblogs.com/lph970417/p/12079432.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!