在Windows上使用Cython进行编译:缺少源文件名

时间:2017-05-25 01:55:34

标签: python python-3.x cython cl cythonize

我正在尝试使用Windows 10上的Cython编译一个hello world示例。 我有视觉工作室2015社区。 Python 3.5.2

我的setup.py看起来像这样:

from distutils.core import setup
from Cython.Build import cythonize

setup (
   name='print hello world',
   ext_modules=cythonize("print_h_w.pyx", compiler_directives=
   {'language_level': 3}),
)

我正在尝试编译的文件如下所示:

print('Hello World')

我用这个命令构建:

python setup.py build_ext --inplace

我一直收到这个错误:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe 
/c /nologo /Ox /W3 /GL /DNDEBUG /MD -
IC:\Users\Paul\AppData\Local\Programs\Python\Python35\include -
IC:\Users\Paul\AppData\Local\Programs\Python\Python35\include "-IC:\Program 
Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files 
(x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files 
(x86)\Windows Kits\10\include\10.0.14393.0\ucrt" "-IC:\Program Files 
(x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files 
(x86)\Windows Kits\10\include\10.0.14393.0\shared" "-IC:\Program Files 
(x86)\Windows Kits\10\include\10.0.14393.0\um" "-IC:\Program Files 
(x86)\Windows Kits\10\include\10.0.14393.0\winrt" "-IC:\Program Files 
(x86)\Windows Kits\10\Include\10.0.14393.0\ucrt\" /Tcprint_h_w.c 
/Fobuild\temp.win-amd64-3.5\Release\print_h_w.obj
cl : Command line error D8003 : missing source filename
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 
14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

我一直在做很多研究但是我已经发现了很多东西。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我认为您应该在cython文件中导入print_h_w.pyx

import cython
print("hello world")