I use the Python C API on Windows using Visual Studio 2008. When I try to use a macro PyDate_Checkand other related macros, they cause an access violation because the static variable PyDateTimeAPI is zero. This variable is initialized using a macro PyDateTime_IMPORTthat needs to be called before using any time macros. I do this when creating a new Python sub-interpreter in a separate thread.
A couple of questions :
- Why the function PyCObject_Importin the macro PyDateTime_IMPORTreturns null. I understand that the null return value is because the module cannot be found. But how can the datetime module not be found? Maybe due to incorrect sys.path in the sub-interpreter? “Also, I call the macro PyDateTime_IMPORTin the right place, should it be right after the sub-interpreter is initialized, or when the Python interpreter is initialized?”
PyDateTime_IMPORT:
#define PyDateTime_IMPORT \
PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import("datetime", \
"datetime_CAPI")`
source
share