_gdal_array import error when bundled with pyinstaller
|Reported by:||dhoese||Owned by:||hobu|
The change described in the following ticket #6801 causes an import error when bundled with the tool pyinstaller. Pyinstaller allows a user to bundle a python script and all of its dependencies in to a single directory or installer.
Traceback (most recent call last): File "test.py", line 2, in <module> from osgeo import gdal_array File "/Users/davidh/repos/git/pyinstaller/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module exec(bytecode, module.__dict__) File "site-packages/osgeo/gdal_array.py", line 164, in <module> ImportError: cannot import name '_gdal_array'
See https://github.com/pyinstaller/pyinstaller/issues/2829 for more details.
From what I can tell the import referenced in #6801 is redundant given the swig import helper stuff on the top of the gdal_array.py module. If I switch the import back to "import _gdal_array", my bundled pyinstaller package works. If I remove that import line, it also works. None of the other GDAL SWIG modules (_gdalconst.so, _gdal.so, _ogr.so, etc) seem to have this issue since they don't have the repeated import in the middle of the module.
I can see why the "from . import _gdal_array" is the correct way of importing something from the current subpackage (osgeo) and I'm not super familiar with standard practice with SWIG so I can understand a "no fix" on this. I do have a workaround I can implement for pyinstaller, but the only reason it seems to be needed is because gdal_array.py does its import differently than other SWIG modules.