I was going to try and use Mechanize for one of my programs so I just tested a bit of code I found on a website when I was searching for a tutorial on mechanize.


I know the site is 2 years old but on all of the other sites it used this same basic format at the beginning of their code:

import mechanize

# Browser
br = mechanize.Browser()

Whenever I run this code I get the following error:

Traceback (most recent call last):
File "C:\Users\Robert\Documents\python\mechanize.py", line 1, in <module>
import mechanize
File "C:\Users\Robert\Documents\python\mechanize.py", line 4, in <module>
br = mechanize.Browser()
AttributeError: 'module' object has no attribute 'Browser'

Does mechanize not work anymore?

5 Years
Discussion Span
Last Post by jacob501

Did you check the content of mechanize.py in documents directory? Looks strange directory name for installing a module. In IDLE there is even special menu option for opening module in file menu.


Hmmm...it's weird because the "help()" function of IDLE tells me that "mechanize" is a module, yet when you open the "Open Module" dialog box (Alt+M) and type "mechanize" it tells me that there is "no module named mechanize"


Either it isn't in your python path (examine sys.path) or it isn't being recognized as a module. Most modules are a file, such as in your case a file named mechanize.py if you have a directory, then to find files within it, you need a file named __init__.py (which might be empty).


It works now. I feel stupid. Sorry! The reason it showed as a module at first before I (just barely) installed it is because I accidentally saved my test program for mechanize as "mechanize.py"



This question has already been answered. Start a new discussion instead.
Be sure to adhere to our posting rules.