[Numpy-discussion] importing multiarraymodule.c in Python embedding

Sebastien Bardeau bardeau@iram...
Wed Feb 7 06:51:31 CST 2007


it seems that I have the same trouble, but using Python under Linux:

> I have run into an interesting issue with multiarraymodule.c with 
> regards to embedding Python in a C application on Windows XP. In the 
> application, the following abbreviated sequence was executed
> 1) Py_Initialize
> 2) numpy is imported
> 3) Py_Finalize
> 4) Py_Initialize
> 5) attempt to import numpy results in an error.

As an example I wrote a small C program that embeds Python. The steps 
are the same as above:
1) Python is initialized (Py_Initialize)
2) Numpy is "manually" imported (import numpy) under an interactive loop 
3) Python is finalized (Py_Finalize)
4) Python is initialized again (Py_Initialize)
5) Attempt to import numpy now fails:

 >>> import numpy
Traceback (most recent call last):
  File "<STDIN>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/numpy/__init__.py", line 36, in 
    import core
  File "/usr/lib/python2.5/site-packages/numpy/core/__init__.py", line 
5, in <module>
    import multiarray
SystemError: dynamic module not initialized properly

I'm using Numpy 1.0 and Python 2.5 under a Fedora Core 6:
Python 2.5 (r25:51908, Nov 15 2006, 14:24:03)
[GCC 4.1.1 20061011 (Red Hat 4.1.1-30)] on linux2

I have not searched further why this happens. I embed Python in a larger 
project and let the choice to the user to start a Python session if he 
needs it. Numpy is automatically imported right after Python 
initialization (because it is needed in my context), so that if user 
starts a session, ends it, and starts a new one, the initialization 
automatically fails at the second time. The solution at the present I 
found is  preventing Python to be finalized (Py_Finalize).

I hope this can help. Thanks.


More information about the Numpy-discussion mailing list