How to compile Pyparsing with Cython on WIndows?

I tried to compile Pyparsing on my Windows machine, but got the following errors:

python setup.py build_ext --inplace running build_ext cythoning pyparsing.pyx to pyparsing.c Error compiling Cython file: ------------------------------------------------------------ ... If C{include} is set to true, the matched expression is also parsed (the skipped text and matched expression are returned as a 2-element list). The C{ignore} argument is used to define grammars (typically quoted strings and comment s) that might contain false matches. """ def __init__( self, other, include=False, ignore=None, failOn=None ): ^ ------------------------------------------------------------ pyparsing.pyx:2764:31: Expected an identifier, found 'include' Error compiling Cython file: ------------------------------------------------------------ ... def __init__( self, other, include=False, ignore=None, failOn=None ): super( SkipTo, self ).__init__( other ) self.ignoreExpr = ignore self.mayReturnEmpty = True self.mayIndexError = False self.includeMatch = include ^ ------------------------------------------------------------ pyparsing.pyx:2769:28: Expected an identifier or literal building 'pyparsing' extension creating build creating build\temp.win32-2.7 creating build\temp.win32-2.7\Release C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe /c /nologo /Ox /MD /W 3 /GS- /DNDEBUG -IC:\Python27\include -IC:\Python27\PC /Tcpyparsing.c /Fobuild\t emp.win32-2.7\Release\pyparsing.obj pyparsing.c pyparsing.c(1) : fatal error C1189: #error : Do not use this file, it is the re sult of a failed Cython compilation. error: command '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.exe"' fa iled with exit status 2 

I compiled with the version of Microsoft Visual C ++ 2008 Express, and the most used Pyparsing module is the latest. Please, does anyone know how to make this work?

+6
source share
2 answers

Sir, I did as you said, but there was another warning about compile time:

     python setup.py build_ext --inplace
     running build_ext
     cythoning pyparsing.pyx to pyparsing.c
     warning: pyparsing.pyx: 413: 8: Unreachable code
     building 'pyparsing' extension
     creating build
     creating build \ temp.win32-2.7
     creating build \ temp.win32-2.7 \ Release
     C: \ Program Files \ Microsoft Visual Studio 9.0 \ VC \ BIN \ cl.exe / c / nologo / Ox / MD / W
     3 / GS- / DNDEBUG -IC: \ Python27 \ include -IC: \ Python27 \ PC /Tcpyparsing.c / Fobuild \ t
     emp.win32-2.7 \ Release \ pyparsing.obj
     pyparsing.c
     C: \ Program Files \ Microsoft Visual Studio 9.0 \ VC \ BIN \ link.exe / DLL / nologo / INCRE
     MENTAL: NO / LIBPATH: C: \ Python27 \ libs / LIBPATH: C: \ Python27 \ PCbuild / EXPORT: initpyp
     arsing build \ temp.win32-2.7 \ Release \ pyparsing.obj / OUT: C: \ Users \ iProsper \ Desktop
     \ pyparsing \ pyparsing.pyd /IMPLIB:build\temp.win32-2.7\Release\pyparsing.lib / MAN
     IFESTFILE: build \ temp.win32-2.7 \ Release \ pyparsing.pyd.manifest
        Creating library build \ temp.win32-2.7 \ Release \ pyparsing.lib and object build \
     temp.win32-2.7 \ Release \ pyparsing.exp
     C: \ Program Files \ Microsoft SDKs \ Windows \ v6.0A \ bin \ mt.exe -nologo -manifest build
     \ temp.win32-2.7 \ Release \ pyparsing.pyd.manifest -outputresource: C: \ Users \ iProsper
     \ Desktop \ pyparsing \ pyparsing.pyd; 2

The warning is actually on line 4: warning: pyparsing.pyx: 413: 8: inaccessible code . Then I changed the line as follows:

     def __getattr __ (self, name):
             if True: #name not in self .__ slots__:
                 if name in self .__ tokdict:
                     if name not in self .__ accumNames:
                         return self .__ tokdict [name] [- 1] [0]
                     else:
                         return ParseResults ([v [0] for v in self .__ tokdict [name]])
                 else:
                     return ""
             else:
                 return none

and then recompile it. One thing I noticed is that even with the warning and editing I did, both of them compiled successfully, but when I tried to test it with the following code:

     from pyparsing import Word, alphas
     greet = Word (alphas) ​​+ ',' + Word (alphas) ​​+ '!'
     greeting = greet.parseString ('Hello, World!')
     print greeting

I got the following error:

     Traceback (most recent call last):
       File "C: \ nwaomachux \ build_pyparsing \ checkout.py", line 1, in 
         from pyparsing import Word, alphas
       File "pyparsing.pyx", line 3414, in init pyparsing (pyparsing.c: 100064)
     AttributeError: 'builtin_function_or_method' object has no attribute 'ANY_VALUE'

I would modify the file further and send it to you to check it out, but I only have a few hours with Pyparsing, so I still do not understand the full source code.

I don’t know which effect moves with the attribute .ANY_VALUE = object () to the beginning def withAttribute (args, * attrDict): the function means. Please, what is the fix? Thanks.

+5
source

I suspect the problem is using "include" as a named parameter, since include is the reserved keyword C. Try editing this __init__ procedure to:

 def __init__( self, other, include_=False, ignore=None, failOn=None ): super( SkipTo, self ).__init__( other ) self.ignoreExpr = ignore self.mayReturnEmpty = True self.mayIndexError = False self.includeMatch = include_ self.asList = False if failOn is not None and isinstance(failOn, basestring): self.failOn = Literal(failOn) else: self.failOn = failOn self.errmsg = "No match found for "+_ustr(self.expr) 

That is, simply add '_' to the parameter name, to the parameter list, and to one line that refers to it. This will make your Cython-compiled pyparsing a little option from the standard release, but I have not seen the heavy use of this option.

Good luck, please post in your pyparsing wiki a discussion on the home page of your Cython-izing experience and any information on how this could speed up your pyparsing process.

+4
source

Source: https://habr.com/ru/post/958054/


All Articles