py2exe and numarray

Thomas Heller theller at python.net
Fri Aug 8 15:41:13 EDT 2003


Maurício Caliggiuri Inforçati <mauricio.inforcati at cenpra.gov.br> writes:

> > class Teste:
> >
> >   def __init__(self):
> >
> >       a = array("1","1")
> >       print a
> >
> >
> > if __name__ == '__main__' :
> >     Teste()

> Sorry, Thomas
> I forgot on line:
> "from numarray import array"
>
> The entire code is exactly this above!
> I use python22 and numarray0.6 (for py22)
>
> The exe is generated but I cant run it!
> This is the output error:
>
> Fatal Python error: Can't import module 'numarray.libnumarray'
> abnormal program termination
>
>  Mauricio
This gives a clue, at least.
So the next step would be to run
  python setup.py py2exe -i numarray.libnumarray

Having done this, you get this when running the exe:

Traceback (most recent call last):
  File "<string>", line 1, in ?
[... several lines deleted]
  File "imputil.pyc", line 93, in _import_hook
  File "imputil.pyc", line 347, in _do_import
  File "imputil.pyc", line 271, in _import_one
  File "<string>", line 128, in _process_result
  File "numarray\_ufuncall.pyc", line 13, in ?
  File "<string>", line 1, in ?
  File "imputil.pyc", line 106, in _import_hook
ImportError: No module named _ufuncBool

Not quite there, but we're making progress.
So:
  python setup.py py2exe -i "numarray.libnumarray,numarray._ufuncBool"

Then, we get something similar like the above traceback. This time, the
last line of the traceback is:

  File "imputil.pyc", line 106, in _import_hook
ImportError: No module named _ufuncInt8

We continue the above a few times, then we discover that abviously
py2exe (or modulefinder, to be precise) has problems finding the .pyd
files in the numarray package. Unfortunately, '--packages numarray'
also doesn't find them - seems like a bug in py2exe.

But the mechanisms to work around this are there. Instead of
constructing a giant command line listing all the stuff, write a
setup.cfg file and place it in the directory where setup.py resides.
This is the contents, it lists all the numarray extension modules:

<setup.cfg>
[py2exe]
includes=numarray.libnumarray,
   numarray.memory,
   numarray._bytes,
   numarray._chararray,
   numarray._conv,
   numarray._converter,
   numarray._ndarray,
   numarray._numarray,
   numarray._operator,
   numarray._sort,
   numarray._ufunc,
   numarray._ufuncBool,
   numarray._ufuncComplex32,
   numarray._ufuncComplex64,
   numarray._ufuncFloat32,
   numarray._ufuncFloat64,
   numarray._ufuncInt16,
   numarray._ufuncInt32,
   numarray._ufuncInt64,
   numarray._ufuncInt8,
   numarray._ufuncUInt16,
   numarray._ufuncUInt32,
   numarray._ufuncUInt8
</setup.cfg>

Running 'python setup.py py2exe', and running the resulting executable:
C:\test>dist\test\test.exe
[49]

C:\test>

Bingo, it works!

Thomas




More information about the Python-list mailing list