请原谅我的简单问题。我刚刚开始使用Matplotlib,我遇到了一些困难。
我可以在没有问题的情况下运行以下解释器:
>>> from pylab import *
>>> plot([1,2,3])
>>> show()
上面的代码生成了一个漂亮的图表。
但是,如果我将以下代码放在一个文件中并运行它,我会收到一个错误:
#!/usr/bin/env python
# encoding: utf-8
import sys
import os
from pylab import *
plot([1,2,3])
show()
以下是错误消息:
Traceback (most recent call last):
File "/Users/sbrown/Desktop/new1.py", line 12, in <module>
from pylab import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pylab.py", line 1, in <module>
from matplotlib.pylab import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/__init__.py", line 133, in <module>
from matplotlib.rcsetup import (defaultParams,
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 19, in <module>
from matplotlib.colors import is_color_like
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/colors.py", line 54, in <module>
import matplotlib.cbook as cbook
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/cbook.py", line 15, in <module>
import new
File "/Users/sbrown/Desktop/new.py", line 2, in <module>
plot([1,2,3])
NameError: name 'plot' is not defined
>>>
知道问题可能是什么?提前感谢您提供的任何帮助!
答案 0 :(得分:9)
您的桌面上的文件看起来与标准Python new
模块相同:
>>> import new
>>> new
<module 'new' from '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/new.pyc'>
重命名或删除$HOME/Desktop/new.py
,然后重试。