我有一個運行得太慢的巨大Python代碼。我不想用C重寫我的整個代碼,所以我做了一些研究,並且遇到了Cython。我被告知我的Python代碼保存爲.pyx並創建一個setup.py文件,將「cytonize」我的代碼,然後將其編譯成C.Cython文件無法編譯
然而,當我鍵入C:/Users/loic/Documents/maido-cython/setup.py build_ext –inplace
我得到一個錯誤:
Compiling C:/Users/loic/Documents/maido-cython/maido-cython.pyx because it changed.
[1/1] Cythonizing C:/Users/loic/Documents/maido-cython/maido-cython.pyx
Error compiling Cython file:
------------------------------------------------------------
[unprintable code]
------------------------------------------------------------
Documents\maido-cython\maido-cython.pyx:1:0: 'maido-cython' is not a valid module name
Traceback (most recent call last):
File "C:\Users\loic\Documents\maido-cython\setup.py", line 9, in <module>
ext_modules = cythonize("C:/Users/loic/Documents/maido-cython/maido-cython.pyx"),
File "C:\Python27\lib\site-packages\Cython\Build\Dependencies.py", line 934, in cythonize
cythonize_one(*args)
File "C:\Python27\lib\site-packages\Cython\Build\Dependencies.py", line 1056, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: C:/Users/loic/Documents/maido-cython/maido-cython.pyx
下面的代碼(maido-cython.py
)和我用(不要擔心,我上傳它在我自己的谷歌賬戶)的4個numpy的文件(******_maido_856x512.npy
):https://drive.google.com/drive/folders/0B7P95aWmH4DUek9xcEROb0FQR0E
以下是我在我的設置文件中寫道: :
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
from Cython.Build import cythonize
setup(name = "graphique",
ext_modules = cythonize("C:/Users/loic/Documents/maido-cython/maido-cython.pyx"),
)
有人能告訴我我做錯了嗎?
編輯:
我把你的意見和更改的文件。我也改變了上傳的鏈接:我還有一個問題https://drive.google.com/drive/folders/0B7P95aWmH4DUcFY0X3JycGlacDQ
當我輸入C:/Users/loic/Documents/maido/setup.py build_ext –inplace
具有與冒號做「:」
Compiling C:\Users\loic\Documents\maido\maido_cython.pyx because it changed.
[1/1] Cythonizing C:\Users\loic\Documents\maido\maido_cython.pyx
Error compiling Cython file:
------------------------------------------------------------
...
def metFeuForet():
""" propage le feu a toute la foret pour N etape a l'aide de la fonction propageFeu """
path = "C:\Users\loic\Documents\maido"
^
------------------------------------------------------------
Documents\maido\maido_cython.pyx:258:14: Invalid unicode escape '\U'
Traceback (most recent call last):
File "C:\Users\loic\Documents\maido\setup.py", line 9, in <module>
ext_modules = cythonize("C:\Users\loic\Documents\maido\maido_cython.pyx"),
File "C:\Python27\lib\site-packages\Cython\Build\Dependencies.py", line 934, in cythonize
cythonize_one(*args)
File "C:\Python27\lib\site-packages\Cython\Build\Dependencies.py", line 1056, in cythonize_one
raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: C:\Users\loic\Documents\maido\maido_cython.pyx
我沒有找到對應的Unicode字符。我應該添加什麼?
'maido-cython' =>'maido_cython'。文件名必須是有效的模塊名稱。 –
另外,請勿使用相同的基本名稱命名'.pyx'和'.py'文件。 –
謝謝,我編輯了我的問題,因爲我有另一個問題。 –