Embedding numpy works once, but not twice??

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Sun Feb 1 03:43:43 EST 2009


En Sun, 01 Feb 2009 03:47:27 -0200, Deepak Chandran  
<dchandran1 at tinkercell.com> escribió:

> 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 problem is not with NumPy. You can't run Py_Initialize/Py_Finalize  
more than once. Python doesn't have any mechanism to un-initialize loaded  
modules, and any static data that NumPy had initialized the first time it  
is imported becomes invalid the second time.
Call Py_Initialize at the start of your program, and Py_Finalize at the  
end, never more than once.

-- 
Gabriel Genellina




More information about the Python-list mailing list