Opened 16 months ago
Last modified 16 months ago
#71926 assigned defect
py-opengl: OpenGL.error.Error: Attempt to retrieve context when no valid context
| Reported by: | krotalias | Owned by: | jmroot (Joshua Root) |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | ports | Version: | 2.10.5 |
| Keywords: | Cc: | ||
| Port: | py-opengl |
Description (last modified by ryandesign (Ryan Carsten Schmidt))
Python opengl used to work with freeglut. However, now there is a problem getting the context. Editing
/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/OpenGL/platform/ctypesloader.py
and replacing
fullName = util.find_library( name ) for
fullName = "/System/Library/Frameworks/{}.framework/{}".format(name,name)
as discussed here -- https://github.com/PixarAnimationStudios/OpenUSD/issues/1372 -- fixes the problem.
The monkeypatch_ctypes approach also works, and one must import it before opengl in any code using pyopengl:
# https://github.com/PixarAnimationStudios/OpenUSD/issues/1372
# /opt/local/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/OpenGL/platform/ctypesloader.py
def monkeypatch_ctypes():
import os
import ctypes.util
uname = os.uname()
if uname.sysname == "Darwin" and uname.release >= "20.":
real_find_library = ctypes.util.find_library
def find_library(name):
if name in {"OpenGL", "GLUT"}: # add more names here if necessary
return f"/System/Library/Frameworks/{name}.framework/{name}"
return real_find_library(name)
ctypes.util.find_library = find_library
return
monkeypatch_ctypes()
The version of the python used is irrelevant. The bug also appears for python 3.13 I tested on macos Catalina and Monterey, because I do not have access to a newer Mac.
Thank you.
Change History (1)
comment:1 Changed 16 months ago by ryandesign (Ryan Carsten Schmidt)
| Cc: | jmroot removed |
|---|---|
| Description: | modified (diff) |
| Keywords: | opengl freeglut python removed |
| Owner: | set to jmroot |
| Status: | new → assigned |
| Summary: | OpenGL.error.Error: Attempt to retrieve context when no valid context → py-opengl: OpenGL.error.Error: Attempt to retrieve context when no valid context |
