5

I installed mechanize via pip and get an errer when I import the module:

$ python
Python 3.5.2 (default, Jun 28 2016, 08:46:01) 
[GCC 6.1.1 20160602] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mechanize
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.5/site-packages/mechanize/__init__.py", line 119, in <module>
    from _version import __version__
ImportError: No module named '_version'

The file -version.py is present in the site-packages directory:

$ ls /usr/lib/python3.5/site-packages/mechanize
_auth.py               __init__.py           _response.py
_beautifulsoup.py      _lwpcookiejar.py      _rfc3986.py
_clientcookie.py       _markupbase.py        _sgmllib_copy.py
_debug.py              _mechanize.py         _sockettimeout.py
_firefox3cookiejar.py  _mozillacookiejar.py  _testcase.py
_form.py               _msiecookiejar.py     _urllib2_fork.py
_gzip.py               _opener.py            _urllib2.py
_headersutil.py        _pullparser.py        _useragent.py
_html.py               __pycache__           _util.py
_http.py               _request.py           _version.py

What am I missing?

1
  • Mechanize is also unsupported, use requests Commented Aug 24, 2016 at 19:06

2 Answers 2

7

If you look at setup.py you'll see mechanize is a Python 2.x package:

Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 2.4
Programming Language :: Python :: 2.5
Programming Language :: Python :: 2.6
Programming Language :: Python :: 2.7

Apart from that, you can see in mechanize/__init__.py that all imports are relative:

from _version import __version__

instead of explicit:

from ._version import __version__

In python 3, this results in import errors.

There's an issue opened for Py3 support and it lists some alternatives you could try. That, or port it :-).

Sign up to request clarification or add additional context in comments.

2 Comments

I installed with pip3... where can I find the setup.py?
I linked the setup.py in the source for mechanize. pip3 can still install a python 2 package. Your specific issue is relative imports here, mechanize seems to use a lot of them in its __init__ file. In Python 3 you need to be explicit about your imports.
0

it't work for me, coppy file _version to use this command

cp -R __version /usr/local/lib/python3.9

to determine pac

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.