13

I am trying to run this simple gym example on the new macOs Big Sur.

import gym
env = gym.make('CartPole-v0')
env.reset()
for _ in range(1000):
    env.render()
    env.step(env.action_space.sample()) # take a random action
env.close()

However, I am running into this

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gym/envs/classic_control/rendering.py", line 25, in <module>
    from pyglet.gl import *
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyglet/gl/__init__.py", line 95, in <module>
    from pyglet.gl.lib import GLException
  File "/Library/Frameworks/Python.framework/Versions/3.7/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 "/Library/Frameworks/Python.framework/Versions/3.7/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 "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyglet/lib.py", line 124, in load_library
    return self.load_framework(kwargs['framework'])
  File "/Library/Frameworks/Python.framework/Versions/3.7/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 "/Users/.../myFileName.py", line 19, in <module>
    env.render()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gym/core.py", line 240, in render
    return self.env.render(mode, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/gym/envs/classic_control/cartpole.py", line 174, in render
    from gym.envs.classic_control import rendering
  File "/Library/Frameworks/Python.framework/Versions/3.7/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 followed this and this discussion but could not find a working solution. Could someone help?


Additional Info

  • macOs Big Sur 11.0.1
  • Python 3.9.0
  • PyOpenGL==3.1.5
  • pyglet==1.5.11 (after running pip install pyglet==1.5.11 it shows Requirement already satisfied: pyglet==1.5.11 in /Library/Frameworks/..., however, when running print(pyglet.version) in my script I am getting 1.5.0). How can I change that to 1.5.11 even though it is already installed?
PeeteKeesel
  • 634
  • 1
  • 7
  • 18
  • Does this help? - https://stackoverflow.com/questions/63475461/unable-to-import-opengl-gl-in-python-on-macos – CryptoFool Dec 06 '20 at 22:28
  • @Steve no it doesn't, the answer points to hardcoding this path `/System/Library/Frameworks/OpenGL.framework/OpenGL` which is the source of the problem – watch-this Dec 08 '20 at 17:50

2 Answers2

19

Try pip install pyglet==1.5.11

Source - https://github.com/openai/gym/issues/2101

  • This will throw a strange warning about compatibility with OpenAI gym module, however still worked for getting the gym environment to boot for me. – Tim Jan 19 '21 at 06:10
  • 3
    I have just installed the latest pyglet version forcing the version (`pip install pyglet==1.5.15`). As @Tim says, you get a dependency warning (ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. gym 0.18.0 requires pyglet<=1.5.0,>=1.4.0, but you have pyglet 1.5.15 which is incompatible.), but I successfully got Open AI gym environment rendering working on a Mac running macOS Big Sur 11.2.3. – Roberto Vázquez Lucerga Mar 17 '21 at 17:09
0

I have macOS Big Sur 11.1 and Pychram CE 2020.3 with

  1. Python 3.7
  2. Tensorflow 1.14.0 (for A2C)
  3. PyOpenGL 3.1.5
  4. Gym 0.17.3
  5. Pyglet 1.5.14

Then I installed pyglet 1.5.14 from Python Interpreter. It is worth mentioning that

pip install pyglet==1.5.14

did not solve the error but pyglet 1.5.14 from Python Interpreter worked.

Deepak Ingole
  • 96
  • 1
  • 6