使用build_ext编译Cython代码将返回错误,除非我在中完全指定目录设置.py

2024-09-30 14:32:10 发布

您现在位置:Python中文网/ 问答频道 /正文

这里的第一个问题-感觉像一个愚蠢的问题,我试图寻找不同的东西,但找不到答案。在

我遵循Cython getting started guide并尝试构建我的第一个模块。我的'测试.pyx'文件是:

def say_hello_to(name):
    print("Hello %s!" % name)

我的'设置.py'文件是:

^{pr2}$

两个文件都位于同一个目录中,即C:\testing。然后我运行:

python setup.py build_ext --inplace

然后得到以下错误(我使用的是Python设置):

C:\Users\Jill3\Anaconda\Scripts\gcc.bat -DMS_WIN64 -mdll -O -Wall -IC:\Users\Jill3\Anaconda\include -IC:\Users\Jill3\Anaconda\PC -c testing.c -o build\temp.win-amd64-2.7\Release\testing.o
gcc.exe: error: testing.c: No such file or directory
gcc.exe: fatal error: no input files

目录中会出现一个testing.c文件,但没有其他文件。在

如果我改变设置.py文件收件人:

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

setup(
    name = 'Hello world app',
    ext_modules = cythonize("C:\\testing\\testing.pyx")

然后一切如期而至。在

我有什么需要调整的吗?还是每次都要包括整个目录路径?在

编辑:我尝试在设置.py文件:

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

setup(
    name = 'Hello world app',
    ext_modules = cythonize("testing.pyx"),
    include_dirs = [os.getcwd()]
)

这反映在输出中,但我仍然看到相同的错误:

C:\Users\Jill3\Anaconda\Scripts\gcc.bat -DMS_WIN64 -mdll -O -Wall -IC:\testing -IC:\Users\Jill3\Anaconda\include -IC:\Users\Jill3\Anaconda\PC -c testing.c -o build\temp.win-amd64-2.7\Release\testing.o
gcc.exe: error: testing.c: No such file or directory
gcc.exe: fatal error: no input files

Tags: 文件namefrompyimportsetuperroranaconda