gpt4 book ai didi

python - 导入错误 : No module named '_version' when importing mechanize

转载 作者:太空狗 更新时间:2023-10-30 02:17:47 24 4
gpt4 key购买 nike

我通过 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 存在于站点包目录中:

$ 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

我错过了什么?

最佳答案

如果你看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.

有一个 issuePy3 支持而打开,它列出了一些您可以尝试的替代方案。那个,或者移植它 :-)。

关于python - 导入错误 : No module named '_version' when importing mechanize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39130957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com