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
Open
Conversation
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.