Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load/find OpenGL on MacOS #1372

Open
asierralozano opened this issue Oct 27, 2020 · 22 comments
Open

Unable to load/find OpenGL on MacOS #1372

asierralozano opened this issue Oct 27, 2020 · 22 comments

Comments

@asierralozano
Copy link

asierralozano commented Oct 27, 2020

Description of Issue

Hello!

I've installed USD on macOS Big Sur with this little fix, and although the build went successfully, as soon as I try to open USDView, it fails to load OpenGL

Traceback (most recent call last):
  File "/opt/local/USD/lib/python/pxr/Usdviewq/stageView.py", line 1632, in paintGL
    from OpenGL import GL
  File "/usr/local/lib/python2.7/site-packages/OpenGL/GL/__init__.py", line 3, in <module>
    from OpenGL import error as _error
  File "/usr/local/lib/python2.7/site-packages/OpenGL/error.py", line 12, in <module>
    from OpenGL import platform, _configflags
  File "/usr/local/lib/python2.7/site-packages/OpenGL/platform/__init__.py", line 36, in <module>
    _load()
  File "/usr/local/lib/python2.7/site-packages/OpenGL/platform/__init__.py", line 33, in _load
    plugin.install(globals())
  File "/usr/local/lib/python2.7/site-packages/OpenGL/platform/baseplatform.py", line 97, in install
    namespace[ name ] = getattr(self,name,None)
  File "/usr/local/lib/python2.7/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
    value = self.fget( obj )
  File "/usr/local/lib/python2.7/site-packages/OpenGL/platform/darwin.py", line 62, in GetCurrentContext
    return self.CGL.CGLGetCurrentContext
  File "/usr/local/lib/python2.7/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
    value = self.fget( obj )
  File "/usr/local/lib/python2.7/site-packages/OpenGL/platform/darwin.py", line 45, in CGL
    def CGL(self): return self.GL
  File "/usr/local/lib/python2.7/site-packages/OpenGL/platform/baseplatform.py", line 15, in __get__
    value = self.fget( obj )
  File "/usr/local/lib/python2.7/site-packages/OpenGL/platform/darwin.py", line 41, in GL
    raise ImportError("Unable to load OpenGL library", *err.args)
ImportError: ('Unable to load OpenGL library', 'dlopen(OpenGL, 10): image not found', 'OpenGL', None)

OpenGL is successfully installed. I'm able to import it with no problems on a python interpreter.

System Information (OS, Hardware)

macOS Big Sur Beta 10 (MacOS 11.0 Beta (20A5395g))
MacBookPro 2016 Late (i7)

Package Versions

USD v20.11
PyOpenGL v3.1.5
PySide2 v5.13.2

@asierralozano
Copy link
Author

It looks like the issue is getting a fix python/cpython#21241
In the meantime, you can fix this issue by editing PyOpenGL file OpenGL/platform/ctypesloader.py, and changing the line

fullName = util.find_library( name )

to

fullName = '/System/Library/Frameworks/OpenGL.framework/OpenGL'

@asierralozano asierralozano changed the title Unable to load OpenGL on MacOS Unable to load/find OpenGL on MacOS Oct 27, 2020
@meshula
Copy link
Member

meshula commented Oct 27, 2020

The fix to finding Python's cached sys dylibs is now tracked on this PR:

python/cpython#22855

It's currently in review.

@meshula
Copy link
Member

meshula commented Oct 27, 2020

Thanks @asierralozano for finding that!

@jilliene
Copy link

Filed as internal issue #USD-6450

@sosbill
Copy link

sosbill commented Nov 27, 2020

It looks like the issue is getting a fix python/cpython#21241
In the meantime, you can fix this issue by editing PyOpenGL file OpenGL/platform/ctypesloader.py, and changing the line

fullName = util.find_library( name )

to

fullName = '/System/Library/Frameworks/OpenGL.framework/OpenGL'

thx for answer, but my '/System/Library/Frameworks/OpenGL.framework' doesn't have a file named OpenGL

@DanielAmmar
Copy link

It looks like the issue is getting a fix python/cpython#21241
In the meantime, you can fix this issue by editing PyOpenGL file OpenGL/platform/ctypesloader.py, and changing the line

fullName = util.find_library( name )

to

fullName = '/System/Library/Frameworks/OpenGL.framework/OpenGL'

thx for answer, but my '/System/Library/Frameworks/OpenGL.framework' doesn't have a file named OpenGL

You don't actually need the binary there, just change the fullName variable as suggested.

@AnaLarralde
Copy link

It worked perfectly!! (mind the indentation when changing the line!!)
Thank you very much!

@grapegrap
Copy link

grapegrap commented Dec 16, 2020

I tried this fix but still get the same error as before. Any suggestions? Thanks!

The code:
Screen Shot 2020-12-16 at 3 36 18 PM

@anjok
Copy link

anjok commented Dec 26, 2020

better use

"""Load a given library for Windows systems

returns the ctypes C-module object
"""
fullName = "/System/Library/Frameworks/{}.framework/{}".format(name,name)

instead, as otherwise GLUT won't load.

@zyf674
Copy link

zyf674 commented Dec 29, 2020

Can anyone tell me where is this file OpenGL/platform/ctypesloader.py? I'm not able to locate it on my Mac

@birdsofbluesky
Copy link

Can anyone tell me where is this file OpenGL/platform/ctypesloader.py? I'm not able to locate it on my Mac

@zyf674 this worked for me

find / -name ctypesloader.py 2>/dev/null

@asierralozano
Copy link
Author

It looks like they have fixed this issue on the latest USD release! (21.02)

@MattSingbeil
Copy link

I had the same issue but it also persisted with the GLUT framework as well. Below was my work around piggy backing off of suggested edits here.

# fullName = util.find_library( name )
if "opengl" in name.lower():
    fullName = '/System/Library/Frameworks/OpenGL.framework/OpenGL'
elif "glut" in name.lower():
    fullName = '/System/Library/Frameworks/GLUT.framework/GLUT'
else:
    fullName = util.find_library( name )

@pengzhouzp
Copy link

pengzhouzp commented Mar 30, 2021

It looks like the issue is getting a fix python/cpython#21241
In the meantime, you can fix this issue by editing PyOpenGL file OpenGL/platform/ctypesloader.py, and changing the line

fullName = util.find_library( name )

to

fullName = '/System/Library/Frameworks/OpenGL.framework/OpenGL'

Hi, I cannot find the ctypesloader.py by find . -name 'ctypesloader.py', thank you for the help!

@YMVio
Copy link

YMVio commented Apr 1, 2021

It looks like the issue is getting a fix python/cpython#21241
In the meantime, you can fix this issue by editing PyOpenGL file OpenGL/platform/ctypesloader.py, and changing the line

fullName = util.find_library( name )

to

fullName = '/System/Library/Frameworks/OpenGL.framework/OpenGL'

Hi, I cannot find the ctypesloader.py by find . -name 'ctypesloader.py', thank you for the help!

Hi, you just need type "ctypesloader.py" in Spotlight Search.

@pifparfait
Copy link

This works for me. Thanks

@rollcat
Copy link

rollcat commented Apr 20, 2021

Another option, if you can't (or don't want to) patch the library source, you can monkey-patch the stdlib ctypes library:

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

@komms
Copy link

komms commented Sep 1, 2021

Can anyone tell me where is this file OpenGL/platform/ctypesloader.py? I'm not able to locate it on my Mac

It should be here: ~/anaconda3/lib/python3.8/site-packages/OpenGL

@luca992
Copy link

luca992 commented Sep 3, 2021

Another option, if you can't (or don't want to) patch the library source, you can monkey-patch the stdlib ctypes library:

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

This is exactly what I needed. 👍

@IvanLiuTW
Copy link

@asierralozano
The post helped solve my failing import issue.
Thank you!

@coreyjadams
Copy link

@luca992 You are the hero I needed today, thank you for this monkey patch from last year!

This solved my issues on Monterey using system Python 3.7.3, and a virtualenv where I install PyOpenGL.

@physicist90
Copy link

IGNORE ALL OF THESE

JUST RUN THIS: pip install PyOpenGL PyOpenGL_accelerate

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

No branches or pull requests