1

I apologize for a newbie Python question.

I have a script that has

import mechanize

which gives the error:

File "/usr/local/lib/python3.5/dist-packages/mechanize/__init__.py", line 122, in <module> from _mechanize import \
ImportError: No module named '_mechanize'

I would think this means the module isn't installed or initialized, but when I open a BASH and type:

$ pip3.5 install mechanize

...this gives the error

Requirement already satisfied: mechanize in /usr/local/lib/python3.5/dist-packages

I looked here and here. The latter comes close, but I think I'm using the right pip edition.

Sorry for what I'm sure is awful newbie nomenclature. I suspect there's a difference between mechanize and _mechanize, but I don't know what it is.

Community
  • 1
  • 1
Suzanne
  • 582
  • 2
  • 11
  • 31

2 Answers2

2

General suggestion: You should be using virtual environments as this prevents problems in packages by containing the packages within each virtual env. Far easier to maintain python module versions in this manner.

On a normal PC you may be able to fix your problem like this (but it won't work on PythonAnywhere):

cd /usr/local/lib/python3.5/dist-packages/mechanize/
python setup.py install

then attempt to import again.

If that fails then try to do the following

pip uninstall mechanize
pip install mechanize
hwjp
  • 15,359
  • 7
  • 71
  • 70
Chinny84
  • 956
  • 6
  • 16
  • Thank you. The first two recommendations didn't work, but creating a virtual environment and moving all the modules into that worked great. Thank you so much. – Suzanne Dec 04 '16 at 16:31
  • funny this is, that last statement was a throw in at the end - lucky I mentioned it! – Chinny84 Dec 04 '16 at 19:07
1

By the way, on PA you should use:

pip3.5 install --user --upgrade mechanize

more info here: https://help.pythonanywhere.com/pages/InstallingNewModules

hwjp
  • 15,359
  • 7
  • 71
  • 70
jgmdavies
  • 31
  • 4