AlchemyAPI gives an error when compiling

580 views Asked by At

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!

2

There are 2 answers

0
Hosam Aly On

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 (e.g. 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)
    
0
shaun_alchemyapi On

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.