2014-03-19 47 views
3

我已經安裝了python3的機械化庫。 https://github.com/adevore/mechanize/tree/python3導入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 

但是,我確定機械化安裝在同一個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 

我不習慣在終端操作,所以我不知道如何解決這個問題。

任何人都可以請幫我解決這個問題嗎?

預先感謝您!

+0

你有沒有機會去使用Python 3? –

回答

2

您提到的git存儲庫使用了import錯誤。 mechanize._html模塊import s _sgmllib_copy預計會得到mechanize._sgmllib_copy,但這種進口方式已在PEP 328中棄用。相反,它應該使用相對的進口,例如from . import _sgmllib_copy

+0

非常感謝您的幫助!那麼,我需要做的是修復「mechanize._html」文件?我沒有看到該HTML文件。 – crzyonez777

+0

支持'mechanize._html'模塊的文件當然叫做'mechanize/_html.py'。 –

1

https://github.com/adevore/mechanize/tree/python3

此分支不包含_sgmllib_copy.py可言。我從主分支中取出這個文件(它需要將print smth更改爲print (smth))。但我仍然不明白應該如何使用導入。在_html.py模塊(它位於機械化文件夾中)使用

from . import _sgmllib_copy as sgmllib

這是錯的?但from . import _beautifulsoup似乎工作。

+0

謝謝你的幫助!我從master分支添加_sqmllib_copy並重新安裝它。現在我有這個錯誤「IndentationError:unexpected indent」... – crzyonez777

+0

所以你可以修復源文件中的這個錯誤。它顯示行號在哪裏出現? 或者你可以嘗試使用我的修復https://drive.google.com/file/d/0B2tqHfR7_fJua2pwNUFmSDlIWnM/edit?usp=sharing 它安裝,但仍對我不起作用 –

+0

也許它不」由於我們的代理服務器,我爲我工作。 –