AlchemyAPI编译时出错
我正在尝试使用 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
有人能帮我解决这个问题吗?
提前谢谢你们!
2 个回答
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。