我正在试用AlchemyAPI 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有人能帮我解决这个问题吗?
提前谢谢你!
发布于 2012-03-09 03:11:55
我为AlchemyAPI工作。
我们刚刚修改了Python SDK,删除了对PyXML的依赖(如果您使用的是Python2.4和更早版本,则需要lxml)。
请在此处找到新的SDK:http://www.alchemyapi.com/tools/
它支持Python 2和Python 3的所有版本。
发布于 2012-03-05 19:57:44
PyXML是为Python2.4编写的,在Python2.5和2.6中逐渐引入了as关键字。在上面堆栈跟踪的最后一行中,as关键字被用作变量名,这与Python2.6的语法冲突。
您可以通过编辑两个文件,将as变量的名称更改为其他名称(例如axis)来解决此问题:
C:\Python26\lib\site-packages\_xmlplus\xpath\ParsedAbbreviatedRelativeLocationPath.py,第31和32行:ppl)
C:\Python26\lib\site-packages\_xmlplus\xpath\ParsedAbbreviatedAbsoluteLocationPath.py,= ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self') self._middle = ParsedStep.ParsedStep( axis,nt,axis第27和28行:axis = ParsedAxisSpecifier.ParsedAxisSpecifier('descendant-or-self') self._step = ParsedStep.ParsedStep(axis,nt,ppl)
https://stackoverflow.com/questions/8331434
复制相似问题