Search code examples
python-3.xgisgeopandas

Python Module Not Found Error only for Compiled Script with Pyogrio Import


I'm on a Windows 10 work computer with Python 3 installed but not Python 2. Keeping the script simple here. This:

import pyogrio
print(pyogrio.__version__)

runs perfectly fine as a file.py script. When I compile (with pyinstaller) and run it I get the following error:

Traceback (most recent call last):
  File "Simple.py", line 1, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "pyogrio\__init__.py", line 21, in <module>
  File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
  File "pyogrio\core.py", line 21, in <module>
  File "pyogrio\\_io.pyx", line 1, in init pyogrio._io
ModuleNotFoundError: No module named 'pyogrio._geometry'

Looking in pyogrio's site packages folder there is no \_geometry but there are \_geometry.pyx and \_geometry.pyd. I had a similar issue with \_io but I can see in their \_envy.py when the import fails it looks for gdal*.dll. Originally it couldn't find this either but I was able to force it and make it work. No where in any of the visible code does it import or use \_geometry which is why I'm at a loss now. What is it using to replace \_geometry? What do I need to add to my compiler to add in what is missing?


Solution

  • I was making it too complicated. While using Visual Studio Code pylance (the internal guy that checks modules?) was saying there was no pyogrio._geometry. But once it was compiled the import worked fine. Adding it to pyinstaller's --hidden-imports worked fine.