Embedding numpy works once, but not twice??
dchandran1 at tinkercell.com
Sun Feb 1 06:47:27 CET 2009
I have a program in which I have successfully embedded Python. Now, I want
to include NumPy as well (and other modules). I am able to import numpy
once. Then I close the python console in my program and then re-open it.
When I try to import numpy for a second time, the program crashes. Below is
a simple version of the problem.
The main() import numpy twice. The first import works fine -- prints "no
errors.". But the second load crashes the program. What is going on here?
By the way, this is all in Windows (XP and Vista have same problem) using
python25.dll (since numpy does not work for python26.dll). I am using MinGW
int load(char * code)
PyObject *errobj, *errdata, *errtraceback, *pystring;
PyObject *main = PyImport_AddModule("__main__");
PyObject* main_dict = PyModule_GetDict( main );
PyObject * rstring = PyRun_String( code, Py_file_input, main_dict, main_dict
); //the second main_dict was my_program_dict originally
PyErr_Fetch (&errobj, &errdata, &errtraceback);
if (errdata != NULL)
PyObject *s = PyObject_Str(errdata);
char * c = PyString_AS_STRING(s);
printf("%s\n",c); //print any errors
// no errors
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list