embedding python - PyImport_ImportModule returns null

JW jkpangtang at yahoo.com
Wed Mar 5 21:02:21 EST 2003


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.


What am i doing wrong?
Thanks in advance for the help




More information about the Python-list mailing list