1

I am trying the following code:

import gym

env = gym.make('ma_gym:Switch2-v0')
done_n = [False for _ in range(env.n_agents)]
ep_reward = 0

obs_n = env.reset()
while not all(done_n):
    env.render()
    obs_n, reward_n, done_n, info = env.step(env.action_space.sample())
    ep_reward += sum(reward_n)
env.close()

However, when I run it, I get the following error messages:

Advay@advays-mbp evolution-org-main % /Users/Advay/miniforge3/envs/evolution_env/bin/python "/Users/Advay/Library/Mobile Documents/com~apple~CloudDocs/Brown/Research/Rose Lab/evolution-org-main/magym-room-v0/runner.py"
/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/gym/logger.py:34: UserWarning: WARN: Box bound precision lowered by casting to float32
  warnings.warn(colorize("%s: %s" % ("WARN", msg % args), "yellow"))
Traceback (most recent call last):
  File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/gym/envs/classic_control/rendering.py", line 27, in <module>
    from pyglet.gl import *
  File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/pyglet/gl/__init__.py", line 95, in <module>
    from pyglet.gl.lib import GLException
  File "/Users/Advay/miniforge3/envs/evolution_env/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 "/Users/Advay/miniforge3/envs/evolution_env/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 "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/pyglet/lib.py", line 124, in load_library
    return self.load_framework(kwargs['framework'])
  File "/Users/Advay/miniforge3/envs/evolution_env/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.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/Advay/Library/Mobile Documents/com~apple~CloudDocs/Brown/Research/Rose Lab/evolution-org-main/magym-room-v0/runner.py", line 9, in <module>
    env.render()
  File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/ma_gym/envs/switch/switch_one_corridor.py", line 183, in render
    from gym.envs.classic_control import rendering
  File "/Users/Advay/miniforge3/envs/evolution_env/lib/python3.9/site-packages/gym/envs/classic_control/rendering.py", line 29, in <module>
    raise ImportError(
ImportError: 
    Error occurred while running `from pyglet.gl import *`
    HINT: make sure you have OpenGL installed. 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 know that the problem is somewhere in the render step but I unsure how to proceed with debugging. I am currently running the code in a conda virtual environment.

To check if the packages in question were installed correctly, I also tried:

import pyglet
import OpenGL

print("hi")

Which successfully printed "hi", confirming that the packages are installed.

Any help greatly appreciated!

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • 1
    I have found some others with the same issue, and it seems that using `pip install pyglet==1.5.11` is a common solution. This is not working for me unfortunately. [github discussion](https://github.com/pyglet/pyglet/issues/274), [stack overflow post](https://stackoverflow.com/questions/65173684/importerror-cant-find-framework-system-library-frameworks-opengl-framework), [lifesaver code](https://lifesaver.codes/answer/gym-on-mac-os-x-big-sur-2101) – Advay Mansingka Apr 26 '22 at 05:29

0 Answers0