简体   繁体   中英

AlchemyAPI gives an error when compiling

I'm trying out AlchemyAPI_Python-0.6 - PyXml module. I was trying to run the keyword extractor feature of it, but got the following error when trying to compile. I used the keywords.py file given in the examples. I copied all the files underneath the python directory (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

Can some one help me out with this issue, please?

Thank you in advance!

I work for AlchemyAPI.

We just revamped our Python SDK, removing dependencies on PyXML (if you're using Python 2.4 and earlier, you'll need lxml).

Please find the new SDK here: http://www.alchemyapi.com/tools/

It supports all versions of Python 2 and Python 3.

PyXML was written for Python 2.4, and the as keyword was introduced gradually in Python 2.5 and 2.6. In the last line of the stack trace above, the as keyword is used as a variable name, which conflicts with the syntax of Python 2.6.

You can solve this issue by editing two files, changing the name of the as variable to something else (eg axis ):

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM