当前位置: 动力学知识库 > 问答 > 编程问答 >

numpy - Error when importing pylab in python 2.6.6

问题描述:

I'm trying to import pylab using Python 2.6.6 on REHL 6.4.

#!/usr/bin/env python

import os, zipfile,glob, shutil,time,scipy,numpy,matplotlib

from pylab import *

I get the error:

# ./script.py

Traceback (most recent call last):

File "./script.py", line 3, in <module>

from pylab import *

File "/usr/lib64/python2.6/site-packages/pylab.py", line 1, in <module>

from matplotlib.pylab import *

File "/usr/lib64/python2.6/site-packages/matplotlib/pylab.py", line 247, in <module>

from matplotlib.pyplot import *

File "/usr/lib64/python2.6/site-packages/matplotlib/pyplot.py", line 78, in <module>

new_figure_manager, draw_if_interactive, show = pylab_setup()

File "/usr/lib64/python2.6/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup

globals(),locals(),[backend_name])

File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtkagg.py", line 10, in <module>

from matplotlib.backends.backend_gtk import gtk, FigureManagerGTK, FigureCanvasGTK,\

File "/usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtk.py", line 8, in <module>

import gtk; gdk = gtk.gdk

File "/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 64, in <module>

_init()

File "/usr/lib64/python2.6/site-packages/gtk-2.0/gtk/__init__.py", line 52, in _init

_gtk.init_check()

RuntimeError: could not open display

All of scipy, numpy and matplotlib are installed but I still can't import pylab. Is there a problem in the way I'm importing pylab?

网友答案:

fixed using :

import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
分享给朋友:
您可能感兴趣的文章:
随机阅读: