26

I saved mechanize in my Python 2.7 directory. But when I type import mechanize into the Python shell, I get an error message that reads:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import mechanize
ImportError: No module named mechanize
Emperor XLII
  • 13,014
  • 11
  • 65
  • 75
user601828
  • 499
  • 3
  • 7
  • 17

11 Answers11

45

using pip:

pip install mechanize

or download the mechanize distribution archive, open it, and run:

python setup.py install
Corey Goldberg
  • 59,062
  • 28
  • 129
  • 143
19

Try this on Debian/Ubuntu:

sudo apt-get install python-mechanize
evedovelli
  • 2,115
  • 28
  • 28
6

You need to follow the installation instructions and not just download the files into your Python27 directory. It has to be installed in the site-packages directory properly, which the directions tell you how to do.

Daniel DiPaolo
  • 55,313
  • 14
  • 116
  • 115
  • 2
    I looked through their site and didn't find a single mention of the site-packages thing. The readme says not to copy to site-packages the mechanize.x.x.x directory, but rather, the mechanize dir inside of it. that solved my problem – Alkanshel Oct 29 '13 at 07:25
4

I dont know why , but "pip install mechanize" didnt work for me . easy install worked anyway . Try this :

sudo easy_install mechanize
hari_sree
  • 1,508
  • 3
  • 12
  • 24
4

Here's what I did which worked:

yum install python-pip
pip install -U multi-mechanize
beetree
  • 871
  • 2
  • 8
  • 18
3
sudo pip-2.7 install mechanize
EdChum
  • 376,765
  • 198
  • 813
  • 562
opmeitle
  • 195
  • 6
  • 19
2

You need the actual package (the directory containing __init__.py) stored somewhere that's in your system's PYTHONPATH. Normally, packages are distributed with a directory above the package directory, containing setup.py (which you should use to install the package), documentation, etc. This directory is not a package. Additionally, your Python27 directory is probably not in PYTHONPATH; more likely one or more subdirectories of it are.

Wooble
  • 87,717
  • 12
  • 108
  • 131
0

You need to install the python-setuptools package:

apt-get install python-setuptools on Debian-ish systems yum install python-setuptools on Redhat-ish systems

Use sudo if applicable

isedev
  • 18,848
  • 3
  • 60
  • 59
0

install dependencies on Debian/Ubuntu:

$ sudo apt-get install python-pip python-matplotlib

install multi-mechanize from PyPI using Pip:

$ sudo pip install -U multi-mechanize

Shrey Gupta
  • 5,509
  • 8
  • 45
  • 71
0

It seems you need to follow the installation instructions in Daniel DiPaolo's answer to try one of the two approaches below

  1. install easy_install first by running "easy_install mechanize", or
  2. download the zipped package mechanize-0.2.5.tar.gz/mechanize-0.2.5.zip and (IMPORTANT) unzip the package to the directory where your .py file resides (i.e. "the resulting top-level directory" per the instructions). Then install the package by running "python setup.py install".

Hopefully that will resolve your issue!

yangli.liy
  • 101
  • 3
  • 5
0
pip install mechanize

mechanize supports only python 2.

For python3 refer https://stackoverflow.com/a/31774959/4773973 for alternatives.

Cibin
  • 590
  • 1
  • 7
  • 13