views:

103

answers:

0

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 the PyCObject_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-interpreter? - 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")`