2011-11-30 90 views
1

我在試用AlchemyAPI_Python-0.6 - PyXml模塊。我試圖運行它的關鍵字提取器功能,但嘗試編譯時出現以下錯誤。我使用了示例中給出的keywords.py文件。我複製了python目錄下的所有文件(AlchemyAPI.py,keywords.py,api_key.txt)。編譯時AlchemyAPI給出錯誤

Traceback (most recent call last): 
    File "C:\Python26\keywords.py", line 4, in <module> 
    import AlchemyAPI 
    File "C:\Python26\AlchemyAPI.py", line 6, in <module> 
    from xml import xpath 
    File "C:\Python26\lib\site-packages\_xmlplus\xpath\__init__.py", line 112, in <module> 
    from pyxpath import ExprParserFactory 
    File "C:\Python26\lib\site-packages\_xmlplus\xpath\pyxpath.py", line 59, in <module> 
    from xml.xpath.ParsedAbbreviatedRelativeLocationPath import ParsedAbbreviatedRelativeLocationPath 
    File "C:\Python26\lib\site-packages\_xmlplus\xpath\ParsedAbbreviatedRelativeLocationPath.py", line 31 
    as = ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self') 
    ^
SyntaxError: invalid syntax 

有人能幫我解決這個問題嗎?

預先感謝您!

回答

0

PyXML是爲Python 2.4編寫的,as關鍵字是在Python 2.5和2.6中逐步引入的。在上面堆棧跟蹤的最後一行中,關鍵字as用作變量名稱,與Python 2.6的語法衝突。

您可以通過編輯兩個文件,改變as變量的名稱到別的東西(如axis)解決了這個問題:

  • C:\Python26\lib\site-packages\_xmlplus\xpath\ParsedAbbreviatedRelativeLocationPath.py,線31和32:

    axis = ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self') 
    self._middle = ParsedStep.ParsedStep(axis, nt, ppl) 
    
  • C:\Python26\lib\site-packages\_xmlplus\xpath\ParsedAbbreviatedAbsoluteLocationPath.py,第27和28行:

    axis = ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self') 
    self._step = ParsedStep.ParsedStep(axis, nt, ppl) 
    
1

我爲AlchemyAPI工作。

我們剛剛修改了我們的Python SDK,刪除了PyXML的依賴關係(如果您使用Python 2.4及更早的版本,則需要lxml)。

請在這裏找到新的SDK:http://www.alchemyapi.com/tools/

它支持Python 2和Python 3

的所有版本