1

私は古いコンピューターを使用しており、Cython を使用して、作成した Python コードを高速化しようとしていますが、最も単純なスクリプトでも Cython を動作させることができません。

Cythonを介して実行しようとしているpythonコードは次のとおりです。私の知る限り、動作するはずです:

def hw():
    print "Hello World"

if __name__ == "__main__":
    hw()

そして、これが私の端末からの出力です:

C:\PyProjects\_cython>python hw.py
Hello World

C:\PyProjects\_cython>cython hw.py

C:\PyProjects\_cython>gcc hw.c
In file included from hw.c:4:
Python.h:8:22: error: pyconfig.h: No such file or directory
hw.c:457: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx_
PyInt_AsUnsignedLongLong'
hw.c:461: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx_
PyInt_AsLongLong'
hw.c:465: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx_
PyInt_AsSignedLongLong'
hw.c: In function '__Pyx_PyUnicode_Equals':
hw.c:826: error: 'Py_UNICODE' undeclared (first use in this function)
hw.c:826: error: (Each undeclared identifier is reported only once
hw.c:826: error: for each function it appears in.)
hw.c:826: error: expected ';' before 'ch1'
hw.c:827: error: expected ';' before 'ch2'
hw.c:828: error: 'ch1' undeclared (first use in this function)
hw.c:828: error: 'ch2' undeclared (first use in this function)
hw.c: At top level:
hw.c:1204: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx
_PyInt_AsUnsignedLongLong'
hw.c:1274: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx
_PyInt_AsLongLong'
hw.c:1344: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__Pyx
_PyInt_AsSignedLongLong'
hw.c: In function '__Pyx_InitStrings':
hw.c:1564: warning: assignment makes pointer from integer without a cast
hw.c: In function '__Pyx_PyInt_AsSize_t':
hw.c:1669: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'val'
hw.c:1669: error: 'val' undeclared (first use in this function)
hw.c:1670: error: expected ')' before 'LONG_LONG'
hw.c:1672: error: expected ')' before 'LONG_LONG'

私は32ビットのPython 2.7を使用してWindows 7 64ビットを使用しています

4

1 に答える 1

3

ドキュメントをご覧ください。私の経験では、これを行う最も簡単な方法はdistutils、コンパイラに渡すために必要なすべての情報 (ヘッダーの場所、重要なライブラリ、適切な共有オブジェクトを作成するためのコンパイラ オプションなど) を知っているので、それを使用することです。ファイルの書き込みsetup.pyはそれほど難しくありません。ライブラリをインストールしたくない場合はpython setup.py build、共有オブジェクトを実行して、必要なディレクトリにコピーします (ただし、buildディレクトリを見つけるためにディレクトリを少し掘り下げる必要がある場合があります)。

于 2012-07-31T04:05:02.480 に答える