简体   繁体   中英

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:

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. Python is importing your file as the module, instead of importing the mechanize library.

Rename your filename to something other than mechanize.py

Giving files names same as that of the modules imported causes the file to be imported instead of the intended module.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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