我通过pip安装了mechanize并在导入模块时获得了错误:
$ 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'
文件-version.py
出现在site-packages目录中:
$ 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
我错过了什么?
答案 0 :(得分:7)
如果您查看setup.py
,我会看到mechanize
是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
除此之外,您可以在mechanize/__init__.py
中看到所有导入都是相对的:
from _version import __version__
而非显式:
from ._version import __version__
In python 3, this results in import errors.
为Py3
支持打开了issue,它列出了您可以尝试的一些替代方案。那,或移植它: - )。
答案 1 :(得分:0)
它对我不起作用,复制文件 _version 使用此命令
cp -R __version /usr/local/lib/python3.9
确定pac