6

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 モジュールは最新バージョンです。これを機能させる方法を知っている人はいますか?

4

2 に答える 2

5

サー、私はあなたが言ったようにしましたが、コンパイル時の警告がまだありました:

    python setup.py build_ext --inplace
    build_ext の実行
    cythoning pyparsing.pyx から pyparsing.c
    警告: pyparsing.pyx:413:8: 到達できないコード
    「pyparsing」拡張機能の構築
    ビルドの作成
    build\temp.win32-2.7 の作成
    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
    メンタル: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
       ライブラリ build\temp.win32-2.7\Release\pyparsing.lib とオブジェクト 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
    \デスクトップ\pyparsing\pyparsing.pyd;2

警告は実際には 4 行目にあります: warning: pyparsing.pyx:413:8: Unreachable code。次に、行を次のように変更しました。

    def __getattr__(自己、名前):
            True の場合: #name が self.__slots__ にありません:
                if name in self.__tokdict:
                    name が self.__accumNames にない場合:
                        return self.__tokdict[name][-1][0]
                    そうしないと:
                        return ParseResults([ v[0] for v in self.__tokdict[name] ])
                そうしないと:
                    戻る ""
            そうしないと:
                返却なし

そして、それを再コンパイルしました。私が気づいたことの1つは、警告と編集を行っても、両方とも正常にコンパイルされましたが、次のコードでテストしようとしたときです。

    pyparsing import Word、alphas から
    挨拶 = 単語 (アルファ) + ',' + 単語 (アルファ) + '!'
    greeting = greeting.parseString('Hello, World!')
    挨拶を印刷する

次のエラーが発生しました。

    トレースバック (最新の呼び出しが最後):
      ファイル「C:\nwaomachux\build_pyparsing\checkout.py」の 1 行目
        pyparsing import Word、alphas から
      ファイル「pyparsing.pyx」、行 3414、init pyparsing (pyparsing.c:100064)
    AttributeError: 'builtin_function_or_method' オブジェクトに属性 'ANY_VALUE' がありません

ファイルをさらに変更して、チェックアウトするために送信したはずですが、Pyparsing を使用してまだ数時間しか経っていないため、完全なソース コードをまだ把握していません。

withAttribute.ANY_VALUE = object()def withAttribute( args, *attrDict): function の先頭に移動することの効果が何を意味するのかわかりません。お願いします、それの修正は何ですか?ありがとう。

于 2013-11-15T08:07:33.060 に答える
4

include問題は、予約済みの C キーワードであるため、名前付きパラメーターとして 'include' を使用していることだと思います。__init__このルーチンを次のように編集してみてください。

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)

つまり、パラメーター リストとそれを参照する 1 行で、パラメーター名に「_」を追加するだけです。これにより、Cython でコンパイルされた pyparsing が標準リリースからわずかに変更されますが、このパラメーターが頻繁に使用されているのは見たことがありません。

幸運を祈ります。pyparsing wiki のホームページ ディスカッションに投稿して、Cython 化の経験と、これにより pyparsing プロセスがどのように高速化されたかについての情報を投稿してください。

于 2013-11-14T13:28:16.107 に答える