ImportError: no module named "_version" when importing mechanization

I installed the mechanization via pip and got an error while importing 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 is -version.pypresent in the sites 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?

+3
source share
1 answer

If you look setup.py, you will see what mechanizethe package is Python 2.x:

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

In addition, you can see in mechanize/__init__.pythat all imports are relative:

from _version import __version__

instead of explicit:

from ._version import __version__

In python 3, this leads to import errors.

issue Py3 , . : -).

+6

Source: https://habr.com/ru/post/1678512/


All Articles