我是python c扩展的新手。我正在复制打印“hello world”的基本示例。但系统一直说“错误:[WinError 2]系统无法找到指定的文件”。
setup.py
:
from distutils.core import setup, Extension
setup(name = 'myModule',
version = '1.0',
ext_modules = [Extension('myModule', ['myModule.c'])])
myModule.c
:
#include <Python.h>
// Function 1: A simple 'hello world' function
static PyObject* helloworld(PyObject* self, PyObject* args)
{
printf("Hello World\n");
return Py_None;
}
// Our Module's Function Definition struct
// We require this `NULL` to signal the end of our method
// definition
static PyMethodDef myMethods[] = {
{ "helloworld", helloworld, METH_NOARGS, "Prints Hello World" },
{ NULL, NULL, 0, NULL }
};
// Our Module Definition struct
static struct PyModuleDef myModule = {
PyModuleDef_HEAD_INIT,
"myModule",
"Test Module",
-1,
myMethods
};
// Initializes our module using our above struct
PyMODINIT_FUNC PyInit_myModule(void)
{
return PyModule_Create(&myModule);
}
我尝试更改out_string = check_output(['gcc', '-dumpmachine'])
文件中的所有404 cygwincompiler.py
线我可以找到out_string = check_output(['gcc', '-dumpmachine'], shell=True)
“仍然没有运气。
我的代码中有一个基本错误吗?我听说c源文件的名称无关紧要。 Here is the terminal image
最有可能的是,这意味着您没有与您的Python版本对应的MS VC编译器的受支持安装。
有关支持的配置,请参阅https://wiki.python.org/moin/WindowsCompilers。另请注意,您使用的是distutils
而不是推荐的setuptools
。 distutils
仅支持最低限度的编译器设置,请参阅https://wiki.python.org/moin/WindowsCompilers#Distutils_notes。
由于您使用的是Anaconda Python而不是正式版,因此您可能还需要从Anaconda提示符运行build命令,以便正确配置构建环境。