简体   繁体   English

无法从机械化导入浏览器

[英]unable to import browser from mechanize

I am using mechanize for the first time. 我是第一次使用机械化。 If I type the line from mechanize import Browser in python shell (interpreter) it doesn't give any error but when run the same code as a part of a .py file it gives the following error: 如果我在python shell(解释器)中from mechanize import Browser的行from mechanize import Browser则不会出现任何错误,但是当作为.py文件的一部分运行相同的代码时,会出现以下错误:

Traceback (most recent call last):
  File "/home/namit/Codes/BS4/mechanize.py", line 1, in <module>
    import mechanize
  File "/home/namit/Codes/BS4/mechanize.py", line 4, in <module>
    mech = mechanize.Browser()
AttributeError: 'module' object has no attribute 'Browser'

Change your filename from mechanize.py. 从mechanize.py更改文件名。 Python is importing your file as the module, instead of importing the mechanize library. Python将文件导入为模块,而不是导入机械化库。

Rename your filename to something other than mechanize.py 重命名您的文件名,而不是mechanize.py

Giving files names same as that of the modules imported causes the file to be imported instead of the intended module. 提供与导入的模块相同的文件名会导致导入文件而不是预期的模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM