Python:模块没有属性“mechanize”。

3
#!/usr/bin/env python
import mechanize

mech = mechanize.Browser()
page = br.open(SchoolRank('KY'))

提供:

Traceback (most recent call last):
  File "mechanize.py", line 2, in <module>
    import mechanize
  File "/home/jcress/Documents/programming/schooldig/trunk/mechanize.py", line 12, in <module>
    mech = mechanize.Browser()
AttributeError: 'module' object has no attribute 'Browser'

我很困惑。我已经安装了适用于2.6和2.7的模块,但结果相同...

1个回答

18

将您的文件名更改为非mechanize.py。 Python正在将您的文件导入为模块。


4
谢谢您提供这个信息,但在我意识到需要删除相应的 .pyc 文件之前,我仍然卡住了。 - Chris Wallace

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接