Skip to content

Commit

Permalink
Temporary workaround for pyinstaller/pyinstaller#5491
Browse files Browse the repository at this point in the history
Add a runtime hook to macOS bundles that patches `ctypes.util.find_library()`
to return the correct OpenGL framwork path. Necessary, to make PyOpenGL work
within the macOS bundles running on macOS Big Sur.

See pyinstaller/pyinstaller#5491 for details.

To commit is to be reverted once PyInstaller has released a fix for this issue.
  • Loading branch information
papr committed Jan 20, 2021
1 parent c616ffa commit a349031
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deployment/deploy_capture/bundle.spec
Expand Up @@ -52,7 +52,7 @@ if platform.system() == "Darwin":
pathex=["../../pupil_src/shared_modules/"],
hiddenimports=hidden_imports,
hookspath=None,
runtime_hooks=None,
runtime_hooks=["../find_opengl_bigsur.py"],
excludes=["matplotlib"],
datas=data_files_pye3d,
)
Expand Down
2 changes: 1 addition & 1 deletion deployment/deploy_player/bundle.spec
Expand Up @@ -53,7 +53,7 @@ if platform.system() == "Darwin":
pathex=["../../pupil_src/shared_modules/"],
hiddenimports=hidden_imports,
hookspath=None,
runtime_hooks=None,
runtime_hooks=["../find_opengl_bigsur.py"],
excludes=["matplotlib"],
datas=data_files_pye3d,
)
Expand Down
2 changes: 1 addition & 1 deletion deployment/deploy_service/bundle.spec
Expand Up @@ -43,7 +43,7 @@ if platform.system() == "Darwin":
pathex=["../../pupil_src/shared_modules/"],
hiddenimports=hidden_imports,
hookspath=None,
runtime_hooks=None,
runtime_hooks=["../find_opengl_bigsur.py"],
excludes=["matplotlib"],
datas=data_files_pye3d,
)
Expand Down
23 changes: 23 additions & 0 deletions deployment/find_opengl_bigsur.py
@@ -0,0 +1,23 @@
import ctypes.util
import functools


print("Attempting to import OpenGL using patched `ctypes.util.find_library`...")
_find_library_original = ctypes.util.find_library

@functools.wraps(_find_library_original)
def _find_library_patched(name):
if name == "OpenGL":
return "/System/Library/Frameworks/OpenGL.framework/OpenGL"
else:
return _find_library_original(name)

ctypes.util.find_library = _find_library_patched

import OpenGL.GL

print("OpenGL import successful!")
print("Restoring original `ctypes.util.find_library`...")
ctypes.util.find_library = _find_library_original
del _find_library_patched
print("Original `ctypes.util.find_library` restored.")

0 comments on commit a349031

Please sign in to comment.