Skip to content

Fix "DLL load failed" startup crash when the target machine has a registered Python 3.12#2046

Open
monch999 wants to merge 1 commit into
OpenDroneMap:masterfrom
monch999:fix-embedded-python-registry-pythonpath
Open

Fix "DLL load failed" startup crash when the target machine has a registered Python 3.12#2046
monch999 wants to merge 1 commit into
OpenDroneMap:masterfrom
monch999:fix-embedded-python-registry-pythonpath

Conversation

@monch999

@monch999 monch999 commented Jul 6, 2026

Copy link
Copy Markdown

The Windows setup ships an embedded Python build with its ._pth file removed (so that pyvenv.cfg is honored). A side effect is that without a ._pth, python.exe falls back to reading
HKLM/HKCU\Software\Python\PythonCore\3.12\PythonPath from the registry and merges those entries into sys.path.

On any end-user machine that has a registered Python 3.12 install (python.org, Anaconda, etc.), the registered Lib/ and DLLs/ directories take part in module resolution, so stdlib extension modules such as _ctypes.pyd get loaded from the foreign install while their dependent DLLs are not on the search path. ODM then crashes on startup with "ImportError: DLL load failed" as soon as opendm.vmem imports ctypes.

Fix: write a python312._pth next to the embedded python.exe during post-install. When a ._pth is present, sys.path is fully defined by the file and both registry entries and PYTHONPATH/PYTHONHOME are ignored. The file lists the embedded stdlib zip, the embed directory itself, the ODM install root and the venv site-packages, which is exactly the set of paths ODM needs.

The Windows setup ships an embedded Python build with its ._pth file
removed (so that pyvenv.cfg is honored). A side effect is that without
a ._pth, python.exe falls back to reading
HKLM/HKCU\Software\Python\PythonCore\3.12\PythonPath from the registry
and merges those entries into sys.path.

On any end-user machine that has a registered Python 3.12 install
(python.org, Anaconda, etc.), the registered Lib/ and DLLs/ directories
take part in module resolution, so stdlib extension modules such as
_ctypes.pyd get loaded from the foreign install while their dependent
DLLs are not on the search path. ODM then crashes on startup with
"ImportError: DLL load failed" as soon as opendm.vmem imports ctypes.

Fix: write a python312._pth next to the embedded python.exe during
post-install. When a ._pth is present, sys.path is fully defined by the
file and both registry entries and PYTHONPATH/PYTHONHOME are ignored.
The file lists the embedded stdlib zip, the embed directory itself, the
ODM install root and the venv site-packages, which is exactly the set
of paths ODM needs.

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant