Python C Расширения, Visual Studio 2019 выдает ошибки (nullptr, python собственные инструменты разработчика не установлены) - PullRequest
0 голосов
/ 05 мая 2020

Я использую Visual Studio 2019 и python 3.8. Я пытаюсь сделать расширение C для Python, и я пытался во всем разобраться и нашел этот учебник https://docs.microsoft.com/en-us/visualstudio/python/working-with-c-cpp-python-in-visual-studio?view=vs-2019

Я выполнил все инструкции, кроме Visual Studio дает мне несколько ошибок, например Python development files are not installed. Please add the development files, or repair your existing installation. calcmodule C:\Users\Heno\Desktop\nics stuff\tictactoe\calcmodule\calcmodule\calcmodule.vcxproj

Также мне нужно использовать nullptr, но визуальная студия дает мне Error (active) E0020 identifier "nullptr" is undefined calcmodule C:\Users\Heno\Desktop\nics stuff\tictactoe\calcmodule\calcmodule\calcmodule.c

Вот мой код (я не мог ничего заработать, поэтому думаю, мне нужно кое-что исправить. если у вас есть для меня подсказки, скажите, пожалуйста):

#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <Windows.h>
#include <assert.h>
#include <stdlib.h>

//get user input getline(cin, input)
static PyObject* calc_hello(PyObject* self, PyObject* args)
{
    //PyObject *obj_a = NULL;
    char inpMsg;
    char retMsg[] = "Hello back!";

    goto try;
    try :
        assert(!PyErr_Occurred());
    //use assert?

    if (!PyArg_ParseTuple(args, "s", &inpMsg))
    {
        PyErr_SetString(PyExc_ValueError, "couldn't parse tuple.");
        goto except;
    }
    goto finally;
except:
    //Py_XDECREF(inpMsg);
    assert(PyErr_Occurred());
    //inpMsg = NULL;
    //retMsg = NULL;
    finally:
    //Py_XDECREF(objects);
    //Py_DECREF(args);
    //return retVal;
    if (retMsg != nullptr)
    {
        return Py_BuildValue("s", retMsg);
    }
}

static PyMethodDef calc_methods[] = {
  {"hello", (PyCFunction)calc_hello, METH_VARARGS, "hello world func"},
  {nullptr, nullptr, 0, nullptr}
};

static struct PyModuleDef calcmodule =
{
    PyModuleDef_HEAD_INIT,
    "calcmodule",
    "all calculations for tictactoe",
    -1,
    calc_methods
};

PyMODINIT_FUNC PyInit_calc(void)
{
    return PyModule_Create(&calcmodule);
}```

Thank you very much for your help!
...