Код: Выделить всё
PyObject *python_module;
char *module_filename = "/mnt/USB3/C/Python_from_C/python_processes";
Py_Initialize();
python_module = PyImport_ImportModule(module_filename);
if(python_module == NULL)
{
printf
(
"Failed to load module \"%s\"\n",
module_filename
);
getchar();
}
Файл python_processes.py существует. Возвращаемый модуль всегда имеет значение NULL. Функция PyImport_ImportModule() не выдает сообщения об ошибке.
Я пробовал много схем инициализации Python (их слишком много), и все они приводят к тому, что модуль не создается. загружено.
Вот еще одна попытка. Это действительно дает сбой.
Код: Выделить всё
Py_Initialize();
python_file_name_pValue = PyUnicode_DecodeFSDefault("python_processes.py");
python_file = PyImport_Import(python_file_name_pValue);
python_function = PyObject_GetAttrString(python_file, "image_processing");
PyObject *load_python_function3
(
char *python_file_name, char *python_function_name
)
{
PyObject *pName, *pModule, *python_function;
Код: Выделить всё
pName = PyUnicode_FromString(python_file_name);
pModule = PyImport_Import(pName);
if(pModule == NULL)
{
printf("Failed to load python_moduke\n");
getchar();
}
python_function = PyObject_GetAttrString(pModule, python_function_name);
if(python_function == NULL)
{
printf("Failed to load python_function\n");
getchar();
}
return python_function;
Подробнее здесь: https://stackoverflow.com/questions/792 ... ialization