加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 如何在WIndows上使用Cython编译Pyparsing?

发布时间:2020-12-16 03:46:52 所属栏目:百科 来源:网络整理
导读:我试图在我的 Windows机器上编译Pyparsing但是遇到以下错误: python setup.py build_ext --inplacerunning build_extcythoning pyparsing.pyx to pyparsing.cError compiling Cython file:------------------------------------------------------------...
我试图在我的 Windows机器上编译Pyparsing但是遇到以下错误:
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,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 buildtemp.win32-2.7
creating buildtemp.win32-2.7Release
C:Program FilesMicrosoft Visual Studio 9.0VCBINcl.exe /c /nologo /Ox /MD /W
3 /GS- /DNDEBUG -IC:Python27include -IC:Python27PC /Tcpyparsing.c /Fobuildt
emp.win32-2.7Releasepyparsing.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 FilesMicrosoft Visual Studio 9.0VCBINcl.exe"' fa
iled with exit status 2

我使用Microsoft Visual C 2008 Express版进行了编译,使用的Pyparsing模块是最新版本.请问,有谁知道如何使这项工作?

解决方法

先生,我按照你的说法做了,但仍然有编译时警告:

    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 buildtemp.win32-2.7
    creating buildtemp.win32-2.7Release
    C:Program FilesMicrosoft Visual Studio 9.0VCBINcl.exe /c /nologo /Ox /MD /W
    3 /GS- /DNDEBUG -IC:Python27include -IC:Python27PC /Tcpyparsing.c /Fobuildt
    emp.win32-2.7Releasepyparsing.obj
    pyparsing.c
    C:Program FilesMicrosoft Visual Studio 9.0VCBINlink.exe /DLL /nologo /INCRE
    MENTAL:NO /LIBPATH:C:Python27libs /LIBPATH:C:Python27PCbuild /EXPORT:initpyp
    arsing buildtemp.win32-2.7Releasepyparsing.obj /OUT:C:UsersiProsperDesktop
    pyparsingpyparsing.pyd /IMPLIB:buildtemp.win32-2.7Releasepyparsing.lib /MAN
    IFESTFILE:buildtemp.win32-2.7Releasepyparsing.pyd.manifest
       Creating library buildtemp.win32-2.7Releasepyparsing.lib and object build
    temp.win32-2.7Releasepyparsing.exp
    C:Program FilesMicrosoft SDKsWindowsv6.0Abinmt.exe -nologo -manifest build
    temp.win32-2.7Releasepyparsing.pyd.manifest -outputresource:C:UsersiProsper
    Desktoppyparsingpyparsing.pyd;2

警告实际上在第4行:警告:pyparsing.pyx:413:8:无法访问的代码.然后我将该行改为:


    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

然后重新编译它.我注意到的一件事是,即使我发出警告和编辑,它们都成功编译,但是当我尝试使用以下代码进行测试时:


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

我收到以下错误:


    Traceback (most recent call last):
      File "C:nwaomachuxbuild_pyparsingcheckout.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'

我会进一步修改文件并发送给你检查它,但我只有几个小时的Pyparsing,所以我还没有掌握完整的源代码.

我不知道将withAttribute.ANY_VALUE = object()移动到def withAttribute(args,* attrDict)的开头是什么效果:function表示.请问,它有什么问题?谢谢.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读