pyglet: Import Error: Can't find framework %s." % path

When I try to run from pyglet.gl import *

The code line 262 tries to find OpenGL inside the directory /System/Library/Frameworks/OpenGL.framework. https://github.com/pyglet/pyglet/blob/d563b7a001506758a77fde035c22c786476d0093/pyglet/lib.py#L262 The function return None which in turn raise ImportError("Can't find framework %s." % path) # on line 283


System Information

OS: Mac OS Big Sur Public 11.0 Beta (20A5354i).

Darwin Akarshs-MacBook-Pro.local 20.0.0 Darwin Kernel Version 20.0.0: Fri Aug 14 00:25:13 PDT 2020; root:xnu-7195.40.44.151.1~4/RELEASE_X86_64 x86_64

Tree structure of the dir /System/Library/Frameworks/OpenGL.framework in my system.

 akarshjain@Akarshs-MacBook-Pro  /System/Library/Frameworks/OpenGL.framework  tree 
.
├── Libraries -> Versions/Current/Libraries
├── Resources -> Versions/Current/Resources
└── Versions
    ├── A
    │   ├── Libraries
    │   │   ├── 3425AMD
    │   │   │   ├── CVMCompiler
    │   │   │   └── libCoreVMClient.mono.dylib
    │   │   ├── 3600
    │   │   │   ├── CVMCompiler
    │   │   │   └── libCoreVMClient.mono.dylib
    │   │   ├── CVMCompiler
    │   │   ├── CVMServer
    │   │   ├── DumpGPURestart
    │   │   ├── ReportGPURestart
    │   │   ├── libGLVMPlugin.dylib
    │   │   ├── libGLVMPlugin31001.dylib
    │   │   ├── libGLVMPlugin3802.dylib
    │   │   └── libGLVMPlugin3902.dylib
    │   ├── Resources
    │   │   ├── BridgeSupport
    │   │   │   └── OpenGL.bridgesupport
    │   │   ├── CVMSPlugin.exp
    │   │   ├── CVMSPluginAll.exp
    │   │   ├── CVMSPluginNoExec.exp
    │   │   ├── GLByteCodes.arm64.bc
    │   │   ├── GLByteCodes.x86_64.bc
    │   │   ├── GLEngine.bundle
    │   │   │   └── GLEngine
    │   │   ├── GLRendererFloat.bundle
    │   │   │   └── GLRendererFloat
    │   │   ├── Info.plist
    │   │   ├── cvmsConfig.plist
    │   │   └── version.plist
    │   └── _CodeSignature
    │       └── CodeResources
    └── Current -> A

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 33 (11 by maintainers)

Commits related to this issue

Most upvoted comments

I have also been trying to fix these errors while trying to render in Gym (on Big Sur, pyglet 1.5.0, system Python 3.8.2) and I found that two fixes are needed:

  1. Changing the find_framework function in site-packages/pyglet/lib.py to the following (as mentioned above):

def find_framework(path): return '/System/Library/Frameworks/OpenGL.framework/OpenGL'

As @MichaelFeng1997 says, a different error then appears. I see an error when trying to load things from the AppKit framework:

ValueError: dlsym(RTLD_DEFAULT, NSEventTrackingRunLoopMode): symbol not found

  1. Changing the first line of the section commented as APPLICATION KIT (line 197) of site-packages/pyglet/libs/darwin/cocoapy/cocoalibs.py to the following then fixes the remaining error and I have Gym rendering now working!:

appkit = cdll.LoadLibrary('/System/Library/Frameworks/AppKit.framework/AppKit')

It seems that this change in loading from dynamic libraries is affecting other repos. and may affect other places in the pyglet codebase (from a quick search of util.find_library), but I don’t think it’ll take too long to fix these. I’m not sure how to have a fix with backward compatibility though.

Hope that helps anyone with the same problem!

I don’t have a Mac to test this on, but there is this comment under “Known Issues” for the Big Sur beta:

New in macOS Big Sur 11 beta, the system ships with a built-in dynamic linker cache of all system-provided libraries. As part of this change, copies of dynamic libraries are no longer present on the filesystem. Code that attempts to check for dynamic library presence by looking for a file at a path or enumerating a directory will fail. Instead, check for library presence by attempting to dlopen() the path, which will correctly check for the library in the cache. (62986286)

I don’t know if this is the issue or not, but might be worth looking into. pyglet.lib could be modified to return the fully formed path, even though it doesn’t find anything.

Most likely it’s going to be the same in stable Big Sur release. So the issue should be addressed, I guess.

Is there any hack to solve this issue as of now ?

Just found a quick fix : go into pyglet/lib.py file and look for the find_framework(path) function. Then comment the body of the function and just return the path to OpenGL.framework :

def find_framework(path):
        """Implement runtime framework search as described by:

        http://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Concepts/FrameworkBinding.html
        """
        return '/System/Library/Frameworks/OpenGL.framework/OpenGL'

I’m also facing the same issue using the official release of macOS Big Sur.

I’m trying to run env.render() from Gym OpenAI environments but I get this error :

Traceback (most recent call last):
  File "/Users/francoisgoujon/RL_Pallet/lib/python3.7/site-packages/gym/envs/classic_control/rendering.py", line 25, in <module>
    from pyglet.gl import *
  File "/Users/francoisgoujon/RL_Pallet/lib/python3.7/site-packages/pyglet/gl/__init__.py", line 95, in <module>
    from pyglet.gl.lib import GLException
  File "/Users/francoisgoujon/RL_Pallet/lib/python3.7/site-packages/pyglet/gl/lib.py", line 147, in <module>
    from pyglet.gl.lib_agl import link_GL, link_GLU, link_AGL
  File "/Users/francoisgoujon/RL_Pallet/lib/python3.7/site-packages/pyglet/gl/lib_agl.py", line 43, in <module>
    gl_lib = pyglet.lib.load_library(framework='/System/Library/Frameworks/OpenGL.framework')
  File "/Users/francoisgoujon/RL_Pallet/lib/python3.7/site-packages/pyglet/lib.py", line 124, in load_library
    return self.load_framework(kwargs['framework'])
  File "/Users/francoisgoujon/RL_Pallet/lib/python3.7/site-packages/pyglet/lib.py", line 279, in load_framework
    raise ImportError("Can't find framework %s." % path)
ImportError: Can't find framework /System/Library/Frameworks/OpenGL.framework.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pallet.py", line 222, in <module>
    env.render()
  File "/Users/francoisgoujon/RL_Pallet/gym_pallet/envs/pallet_env.py", line 142, in render
    from gym.envs.classic_control import rendering
  File "/Users/francoisgoujon/RL_Pallet/lib/python3.7/site-packages/gym/envs/classic_control/rendering.py", line 32, in <module>
    ''')
ImportError: 
    Error occurred while running `from pyglet.gl import *`
    HINT: make sure you have OpenGL install. On Ubuntu, you can run 'apt-get install python-opengl'.
    If you're running on a server, you may need a virtual frame buffer; something like this should work:
    'xvfb-run -s "-screen 0 1400x900x24" python <your_script.py>'

I checked /System/Library/Frameworks/OpenGL.framework and everything seems to be good in the folder. Can’t find any solutions…

I am facing the same issue. Using the official release of macOS Big Sur.

@ulfarsson I believe that message is normal. I’ve always had it at least

Hardcoding the path can work for the time being, but once the CPython fixes make their way out pyglet should work again without any hacks (point release due out soon). Lets leave this issue open until that starts happening.

If anyone wants to check if their Python is working, try this simple test:

import ctypes.util
path = ctypes.util.find_library('ssl')
print(f'Library path: {path}')

If it returns None, it doesn’t have the fix. Currently, only the OSX system bundled Python is working at the moment.

For reference, the CPython issue can be found here: https://bugs.python.org/issue41100

@ebolotin6 If you can’t wait, you can do what ‘geekstor’ said. This worked for me on Big Sur. You probably need to run ‘XQuartz’ while you run your Python program.

Thank you so much! I just changed the “def find_framework(path)” and now everything works just like before (no additional error).

We have a pull request open to fix this: https://github.com/pyglet/pyglet/pull/284

I’ve just been waiting to get confirmation that it doesn’t break older OSX versions. If anyone here has access to previous releases, and can test it, then we can get that merged in.

@ulfarsson Make sure to update to the latest pyglet release (v1.5.10).

import pyglet
print(pyglet.version)

If I run the code snipped you posted @benmoran56 I get

Library path: /usr/lib/libssl.dylib

However, when running

from pyglet.gl import *

I get the error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/pyglet/gl/__init__.py", line 95, in <module>
    from pyglet.gl.lib import GLException
  File "/usr/local/lib/python3.9/site-packages/pyglet/gl/lib.py", line 147, in <module>
    from pyglet.gl.lib_agl import link_GL, link_GLU, link_AGL
  File "/usr/local/lib/python3.9/site-packages/pyglet/gl/lib_agl.py", line 43, in <module>
    gl_lib = pyglet.lib.load_library(framework='/System/Library/Frameworks/OpenGL.framework')
  File "/usr/local/lib/python3.9/site-packages/pyglet/lib.py", line 124, in load_library
    return self.load_framework(kwargs['framework'])
  File "/usr/local/lib/python3.9/site-packages/pyglet/lib.py", line 279, in load_framework
    raise ImportError("Can't find framework %s." % path)
ImportError: Can't find framework /System/Library/Frameworks/OpenGL.framework.

I’m running this on macOS Big Sur with Python3 from Homebrew

Python 3.9.0 (default, Nov 14 2020, 10:50:03)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin

I’ve merged in the fix from Jerekshoe, which will be in the next point release. My understanding is that this should fix things ONLY for the system Python in Big Sur. Other Python releases will need to wait for upstream CPython fixes.

@ebolotin6 sorry for not getting back to you sooner, but luckily some others have been able to test.