我已经为python3安装了机械化库。https://github.com/adevore/mechanize/tree/python3
但是,当我导入它时,我得到了这个错误。
Python 3.3.3 (default, Dec 30 2013, 16:15:14)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import mechanize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/Username/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/__init__.py", line 122, in <module>
File "/Users/Username/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/_mechanize.py", line 15, in <module>
File "/Users/Username/.virtualenvs/python3/lib/python3.3/site-packages/mechanize-0.2.6.dev_20140305-py3.3.egg/mechanize/_html.py", line 16, in <module>
ImportError: cannot import name _sgmllib_copy但是,我确信mechanize安装在相同的virtualenv目录中。
$ pip freeze
## 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-03-19 14:43:55
您提到的git存储库错误地使用了import。mechanize._html模块import的_sgmllib_copy期望获得mechanize._sgmllib_copy,但这种导入方式在PEP 328中已被弃用。相反,它应该使用相对导入,例如from . import _sgmllib_copy。
发布于 2014-03-19 15:43:44
https://github.com/adevore/mechanize/tree/python3
这个分支根本不包含_sgmllib_copy.py。我从主分支中获取了这个文件(它需要将print smth更改为print (smth))。但是我仍然不明白应该如何使用import。在_html.py模块(位于mechanize文件夹中)中使用
from . import _sgmllib_copy as sgmllib
这是错的吗?但from . import _beautifulsoup似乎正在发挥作用。
https://stackoverflow.com/questions/22496112
复制相似问题