导入机械化时,我在python3中出现了一个错误。
我刚刚在安装python3的虚拟环境中安装了机械设备。
$ which python3
/Users/myname/.virtualenvs/python3/bin/python3
$ pip freeze
mechanize==0.2.5但是,当我试图在python代码中导入机械化时,我会得到这个错误。
import mechanize
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-6b82e40e2c8e> in <module>()
----> 1 import mechanize
/Users/myname/.virtualenvs/python3/lib/python3.3/site-packages/mechanize/__init__.py in <module>()
117 import sys
118
--> 119 from _version import __version__
120
121 # high-level stateful browser-style interface
ImportError: No module named '_version'有人知道如何解决这个问题吗?
我对python很陌生,这些天我一直在研究如何在python中编程。
谢谢你提前帮忙!
更新
我安装了python3机械化。现在我又犯了一个错误。
In [1]: import mechanize
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-6b82e40e2c8e> in <module>()
----> 1 import mechanize
/Users/myname/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/__init__.py in <module>()
120
121 # high-level stateful browser-style interface
--> 122 from ._mechanize import \
123 Browser, History, \
124 BrowserStateError, LinkNotFoundError, FormNotFoundError
/Users/myname/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/_mechanize.py in <module>()
/Users/myname/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/_html.py in <module>()
ImportError: cannot import name _sgmllib_copy我检查了我在工作虚拟环境中安装的内容。我发现了一些警告。
$ pip freeze
cssselect==0.9.1
httplib2==0.8
ipython==1.1.0
lxml==3.2.4
## FIXME: could not find svn URL in dependency_links for this package:
mechanize==0.2.6.dev-20140305
pyquery==1.2.8
Warning: cannot find svn location for mechanize==0.2.6.dev-20140305发布于 2014-06-02 19:11:34
唉,机械化不支持Python3. http://wwwsearch.sourceforge.net/mechanize/faq.html
Python 2.4、2.5、2.6或2.7。Python 3还不受支持。
您可能想在https://github.com/jjlee/mechanize/issues/96上评论这个问题。
更新:我编写了自己的自动化库MechanicalSoup。它是Python3兼容的https://github.com/hickford/MechanicalSoup
发布于 2016-03-11 07:28:51
模块MechanicalSoup将机械和BeautifulSoup合并在同一个库中,可以从Python2.6到3.4使用。
在命令提示符下安装MechanicalSoup:
pip install MechanicalSoup然后导入python,
import mechanicalsoup # Don’t forget to import the new module发布于 2014-03-05 07:02:34
我认为您可能已经安装了Python2版本的机械化,而新的Python3导入语义正在破坏原有的Python 2代码。快速搜索,似乎Python 3对机械化的支持还有点弱。然而,我确实找到了一个Python 3分支。
您可以尝试从我链接到的源代码手动安装。下载完源代码后,更改目录,使您处于机械化目录中。然后在终端中输入$python3 setup.py install。
https://stackoverflow.com/questions/22190503
复制相似问题