【问题标题】:AlchemyAPI gives an error when compilingAlchemyAPI 编译时出错
【发布时间】:2012-01-10 00:18:41
【问题描述】:

我正在试用 AlchemyAPI_Python-0.6 - PyXml 模块。我试图运行它的关键字提取器功能,但在尝试编译时出现以下错误。我使用了示例中给出的keywords.py 文件。我复制了python目录下的所有文件(AlchemyAPI.py、keywords.py、api_key.txt)。

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

有人可以帮我解决这个问题吗?

提前谢谢你!

【问题讨论】:

    标签: python alchemyapi pyxml


    【解决方案1】:

    我为 AlchemyAPI 工作。

    我们刚刚改进了 Python SDK,删除了对 PyXML 的依赖(如果您使用的是 Python 2.4 及更早版本,则需要 lxml)。

    请在此处找到新的 SDK:http://www.alchemyapi.com/tools/

    它支持所有版本的 Python 2 和 Python 3。

    【讨论】:

      【解决方案2】:

      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)
        

      【讨论】:

        猜你喜欢
        • 2011-12-08
        • 2013-12-30
        • 1970-01-01
        • 2012-01-28
        • 2013-08-16
        • 2017-07-13
        • 2014-06-25
        相关资源
        最近更新 更多