In the context of a C/C++ application that invokes python code with the Python/C API the following error occurs when importing the "ssl" python module: "DLL load failed while importing _ssl: The specified procedure could not be found":
Simplified example:
#include <Python.h>
int main(int argc, char* argv[])
{
Py_Initialize();
PyObject *sslmod = PyImport_ImportModule("ssl");
if(sslmod == NULL)
PyErr_Print();
Py_XDECREF(sslmod)
Py_Finalize();
return 0;
}
Environment variables PYTHONPATH and PYTHONHOME are set prior to execution accordingly and other modules are imported without problems. Python used is version 3.11.8 built from source obtained from cpython github repo.
I have tried to initialize Python with 'Py_InitializeFromConfig()' and tried various parameter combinations of PyConfig given without success. I have also tried to import the ssl module from a python script and execute it outside C/C++ and it worked. The only instance when the ssl module is imported without problems from the C/C++ context is when the executable is launched from inside the PYTHONHOME directory that contains '_ssl.pyd' and the respective dll 'libssl-3.dll'. I would like it to be imported no matter where the executable is launched from.