-1

I'm new to python c extension. I'm copying a basic example that prints "hello world". But the system keeps saying "error: [WinError 2] The system cannot find the file specified".

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);
}

I tried changing all the 404 out_string = check_output(['gcc', '-dumpmachine']) lines in the cygwincompiler.py files I could find to out_string = check_output(['gcc', '-dumpmachine'], shell=True)" Still no luck.

Is there a basic mistake in my code? I hear that the c source file's name doesn't matter. Here is the terminal image

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152
Jason Guo
  • 9
  • 3
  • It would be useful to include the entire Traceback in the question itself, because as it is we can't really tell _what_ file your OS is failing to locate. – metatoaster Mar 14 '19 at 02:40
  • @metatoaster, I just added attached another terminal image. Thanks for the reminder. I'm fairly new to the community. – Jason Guo Mar 14 '19 at 04:43
  • What Python version is this? My `_msvccompiler.py` is different. – ivan_pozdeev Mar 14 '19 at 05:01
  • From the looks of it, it looks like you may have Python 3.5.0 installed and that the error relates to its inability to find the Visual Studio 7 installation. – metatoaster Mar 14 '19 at 05:05
  • @metatoaster no, in py 3.5 and 3.6, `_msvccompiler.py:34` is in `_find_vc2015()` while the stack trace refers to `_find_vcvarsall()`. – ivan_pozdeev Mar 14 '19 at 05:07
  • 1
    @ivan_pozdeev I only go by what CPython actually has that is present inside the [tag v3.5.0](https://github.com/python/cpython/commit/fcbe1df4afe10eed49e97bf08ba748f9140a5bf3#diff-d962ba8e352edf080a341706a50c13b0), which points to [this exact line of code](https://github.com/python/cpython/blob/v3.5.0/Lib/distutils/_msvccompiler.py#L34). – metatoaster Mar 14 '19 at 05:11

1 Answers1

0

Most probably, this means that you don't have a supported installation of MS VC compiler corresponding to your Python version.

See https://wiki.python.org/moin/WindowsCompilers on what the supported configurations are. Also note that you are using distutils instead of the recommended setuptools. distutils only supports the bare minimum of compiler setups, see https://wiki.python.org/moin/WindowsCompilers#Distutils_notes .

Since you are using an Anaconda Python rather than the official version, you likely also need to run the build command from an Anaconda prompt for the build environment to be properly configured.

ivan_pozdeev
  • 33,874
  • 19
  • 107
  • 152