[GIS] problems with py2exe, shapely and fiona

fionapy2exepythonshapely

I have a short python script, called test:

import fiona
with fiona.open("C:\\Essai_compil", 'r') as l_Obs_shp: 
    for shp in l_Obs_shp:
        print shp['geometry']

I want to compile with py2exeor PyInstaller. OS: Windows7, Python 2.7 (32-bits),
I've got erros. With py2exe, the 'log.txt' said :

Traceback (most recent call last):
File "test.py", line 1, in <module>
File "fiona\__init__.pyc", line 78, in <module>
File "fiona\collection.pyc", line 7, in <module>
File "fiona\ogrext.pyc", line 12, in <module>
File "fiona\ogrext.pyc", line 10, in __load
ImportError: DLL load failed: %1 n’est pas une application Win32 valide.
ImportError: DLL load failed: %1 is not a valid Win32 application.

With PyInstaller, log says:

File "ogrext.pyx", line 12 in init fiona.ogrext (src/fiona/ogrext.c:19107)
ImportError: cannot import name ogrinit

Problem are related to fiona module or some ogr stuff… I supposed this is not a 32/64 bits problem; all the modules I've used are 32-bits. More surely a DLL problem… Any ideas ?

Best Answer

I had the same issue when packaging a fiona project with py2exe. I think py2exe simply cannot resolve all the fiona dependencies. But fortunately fiona is well behaved: just add it under packages into the py2exe script and it will probably also work for you:

opts = {
  'py2exe': {
    'packages':['fiona'],
    'bundle_files': 3
    }
  }

setup(
      console=[{"script" : "test.py"}],
      options=opts,
      zipfile=None
      )