2011-11-30 67 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

的所有版本