ImportError while Embedding python in C

kaush kaushikbarat at gmail.com
Sat Mar 15 05:10:24 EDT 2008


Hi All,

I have a simple python script saved to "test.py" as

import os
import base64

def Testfunction():
    print "Hello World"
    return

Testfunction()

I am trying to invoke this from a C program as follows

int main(int argc, char* argv[])
{
	Py_Initialize();

	PyObject* main_module = PyImport_AddModule("__main__");

	PyObject* main_dict = PyModule_GetDict(main_module);

	FILE* file_1 = fopen(TestFile, "r");
	PyRun_AnyFile(file_1, TestFile);

  	Py_Finalize();

	return 0;
}

This fails with the error

Traceback (most recent call last):
  File "/home/kaushik/shadowFs/test.py", line 4, in <module>
    import base64
  File "/usr/local/lib/python2.5/base64.py", line 9, in <module>
    import struct
  File "/usr/local/lib/python2.5/struct.py", line 30, in <module>
    from _struct import Struct, error
ImportError: /usr/local/lib/python2.5/lib-dynload/_struct.so:
undefined symbol: PyExc_TypeError

I am able to run test.py successfully from the shell.

What am i missing in importing the base64 library?

Thanks,
Kaushik



More information about the Python-list mailing list