Python Matplotlib:“ImportError:无法导入名称flatten”

时间:2014-01-03 16:02:05

标签: python ubuntu matplotlib

我全新安装了Ubuntu 13.04,并尝试使用python库matlibplot。我通过sudo apt-get install python-matplotlib安装了它,这似乎很成功。但是,然后我尝试使用import matplotlib运行python脚本,我收到以下异常消息:

Traceback (most recent call last):
  File "./simulate.py", line 6, in <module>
    import matplotlib
  File "/usr/lib/pymodules/python2.7/matplotlib/__init__.py", line 165, in <module>
    from matplotlib.rcsetup import (defaultParams,
  File "/usr/lib/pymodules/python2.7/matplotlib/rcsetup.py", line 20, in <module>
    from matplotlib.colors import is_color_like
  File "/usr/lib/pymodules/python2.7/matplotlib/colors.py", line 54, in <module>
    import matplotlib.cbook as cbook
  File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 34, in <module>
    import new
  File "/home/rob/Dropbox/Fourth Year/algo/git/new.py", line 3, in <module>
    from pylab import *
  File "/usr/lib/pymodules/python2.7/pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "/usr/lib/pymodules/python2.7/matplotlib/pylab.py", line 219, in <module>
    from cbook import flatten, is_string_like, exception_to_str, \
ImportError: cannot import name flatten

之前发生了这种情况(我无法绕过它)。似乎没有人遇到过同样的问题。

有谁知道解决方案?

1 个答案:

答案 0 :(得分:2)

问题是我在同一目录中有一个名为new.py的文件。

值得注意的是,您需要删除它并new.pyc来解决问题。