[Numpy-discussion] ImportError: dynamic module does not define init function (initmultiarray)

Dominique Orban dominique.orban@gmail....
Fri Aug 19 18:00:04 CDT 2011

Dear list,

I'm embedding Python inside a C program to pull functions from
user-supplied Python modules. All is well except when the
user-supplied module imports numpy. Requesting a stack trace when an
exception occurs reveals the following:

Traceback (most recent call last):
  File "/Users/dpo/.virtualenvs/matrox/matrox/curve.py", line 3, in <module>
    import numpy as np
  File "/Users/dpo/.virtualenvs/matrox/lib/python2.7/site-packages/numpy/__init__.py",
line 137, in <module>
    import add_newdocs
  File "/Users/dpo/.virtualenvs/matrox/lib/python2.7/site-packages/numpy/add_newdocs.py",
line 9, in <module>
    from numpy.lib import add_newdoc
  File "/Users/dpo/.virtualenvs/matrox/lib/python2.7/site-packages/numpy/lib/__init__.py",
line 4, in <module>
    from type_check import *
  File "/Users/dpo/.virtualenvs/matrox/lib/python2.7/site-packages/numpy/lib/type_check.py",
line 8, in <module>
    import numpy.core.numeric as _nx
  File "/Users/dpo/.virtualenvs/matrox/lib/python2.7/site-packages/numpy/core/__init__.py",
line 5, in <module>
    import multiarray
ImportError: dynamic module does not define init function (initmultiarray)

(here, "curve.py" is the user-supplied module in question.)

The symbol initmultiarray *is* defined in multiarray.so so I'm
wondering if anybody has suggestions as to what the problem may be

A bit of Googling reveals the following:

* The 3rd example of Section 31.2.5 of
http://www.swig.org/Doc1.3/Python.html says

   "This error is almost always caused when a bad name is given to the
shared object file. For example, if you created a file example.so
instead of _example.so you would get this error."

* Item #2 in the FAQ at http://biggles.sourceforge.net/doc/1.5/faq says

  "This is a problem with your module search path. Python is loading
[multiarray].so as a module instead of [multiarray].py"

But I don't have any multiarray.py. I have other multiarray.so's, but
they're not in my search path. And I'm not finding any _multiarray.so
with a leading underscore.

So I am lead to ask: should multiarray.so really be called
_multiarray.so? If not, any idea what the problem is?

I'm using Python 2.7.2 compiled as a framework using Homebrew on OSX
10.6.8 and Numpy 1.6.1 installed from PyPi a day or two ago.

Thanks much in advance!


More information about the NumPy-Discussion mailing list