[英]Getting an error when importing mechanize branch for python3
我已經為python3安裝了mechanize庫。 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
我不習慣在終端上操作,所以我不知道如何解決這個問題。
有誰能幫我解決這個問題?
先感謝您!
您引用的git存儲庫使用import
錯誤。 期望獲得mechanize._sgmllib_copy
的mechanize._html
模塊import
s _sgmllib_copy
,但在PEP 328中不推薦使用這種進口方式。 相反,它應該使用相對導入,例如from . import _sgmllib_copy
from . import _sgmllib_copy
。
https://github.com/adevore/mechanize/tree/python3
該分支根本不包含_sgmllib_copy.py。 我從master分支中獲取了這個文件(它需要更改print smth
to print (smth)
)。 但我仍然不知道應該如何使用import。 在_html.py模塊(它位於mechanize文件夾中)使用
from . import _sgmllib_copy as sgmllib
這是錯的嗎? 但from . import _beautifulsoup
from . import _beautifulsoup
似乎正在運作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.