Embedding Python - time module problem

Bjorn Pettersen BPettersen at NAREX.com
Tue Jun 18 12:11:49 EDT 2002


> From: Richard Townsend [mailto:richardt at edshk.demon.co.uk] 
> 
> I have been having problems embedding Python in a small C 
> program which calls a Python script which, in turn, imports 
> the time module.
> 
> This fails with the error:
> 
> "ImportError: dynamic module does not define init function (inittime)"
> 
> I have simplified this down to a minimal C program which just 
> tries to import the time module. This gives the same error.
> 
>   #include <stdio.h>
>   #include <Python.h>
> 
>   int main(int argc, char **argv) 
>   {
>     PyObject *module;
>     Py_Initialize();
>     module = PyImport_ImportModule("time");
>     if (module == NULL)
>     {
>       PyErr_Print();
>     }
>   }
> 
> If I substitute "os" or "sys" for "time" then no error 
> occurs. However "math" does give a similar error.  
> 
> If I run the interpreter on its own, I can import time and 
> math with no problems. 
> 
> I am using Python 2.2.1 on HP-UX 11i
> 
> Is there something special I need to do to be able to import 
> time and math modules when using embedded Python?

Your example works for me (WinXP). The time module should be compiled
into the Python library, so I'm not sure why your installation is trying
to import it as a dynamic module... but since it is, do you happen to
have a shared library named time somewhere on your path?

Sorry I couldn't be of more help, it's been a while since I saw an HP
box.

-- bjorn





More information about the Python-list mailing list