gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 22:22:43 25 4
gpt4 key购买 nike

我试图在我的 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, 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

我使用 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 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

警告实际上在第 4 行:warning: pyparsing.pyx:413:8: Unreachable code。然后我将行更改为:

    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:\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'

我会进一步修改文件并将其发送给您检查,但我对 Pyparsing 的了解只有几个小时,所以我还没有掌握完整的源代码。

我不知道将 withAttribute.ANY_VALUE = object() 移动到 def withAttribute(args,* attrDict): 函数表示。请问有什么办法解决?谢谢。

关于c++ - 如何在 WIndows 上使用 Cython 编译 Pyparsing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19972937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com