embedding python - PyImport_ImportModule returns null

Lexy Zhitenev zhitenev at cs.vsu.ru
Thu Mar 6 05:22:40 EST 2003


"JW" wrote in message:
news:3607e8e4.0303051802.7ddf1dfd at posting.google.com...
> I am trying to embed python within a c program, but I can't get
> PyImport_ImportModule() command to load my module.
> Please let me know what I'm doing wrong.
>
> --
> #file func.py
> def func1():
> print "inside func1()"
>
> --
> //main.c
> int main()
> {
>         PyObject *pFunc, *pModule;
>         Py_Initialize();
>
> pModule=PyImport_ImportModule("func");  //fileread.py
> if(pModule==NULL)
> {
>
> PyErr_Print();
> fprintf(stderr,"Failed to load \"%s\"\n","func");
> }
> //etc....
> }
>
> ---
> Both main.c and func.py are in the same directory.
> I run main and get the error
> Failed to load "func", meaning that PyImport_ImportModule returns NULL.
>

You aren't doing anything wrong. I've tried to compile your code and it
didn't give me any errors.
I use MinGW GCC 2.95 under Windows 2000. You only forgot to #include
<Python.h>, but I don't think that's the problem.

Possibly, this is your compiler's fault. What compiler are you using, what
arguments are for it?

Lexy.






More information about the Python-list mailing list