PyDateTime_IMPORT macro not initializing PyDateTimeAPI variable
I'm using the Python C API on Windows using Visual Studio 2008. When I attempt to use the PyDate_Check
macro, and other related macros, they cause an access violation because the static variable PyDateTimeAPI is null. This variable is initialized using the PyDateTime_IMPORT
macro which needs calling before using any date time macros. I do this when creating a new Python sub-interpreter on a separate thread.
Couple of questions:
- Why is the thePyCObject_Import
function in the PyDateTime_IMPORT
macro returning null. I understand a null return value is because the module cannot be found. But how can the datetime module not being found? Could it be because of an incorrect sys.path in the sub-inter开发者_运维知识库preter?
- Also, am I calling PyDateTime_IMPORT
macro in the correct place, should it be just after the sub-interpreter is initialized, or when the Python interpreter is initialized?
PyDateTime_IMPORT
definition:
#define PyDateTime_IMPORT \
PyDateTimeAPI = (PyDateTime_CAPI*) PyCObject_Import("datetime", \
"datetime_CAPI")`
I ran into this same problem using G++ and Python 3.2. It has something to do that since PyDateTimeAPI is declared in the header, each file that includes that header gets its own version of the variable.
PyCObject is deprecated in 2.7 and removed in 3.x. PyCapsule_Import() should be used instead of PyCObject_Import()
精彩评论