2

I installed Anaconda and downloaded some code. It´s the classic OpenAI project, in this case Getting Started With OpenAI Gym | Paperspace Blog However, when I type

env.render(mode = “human”)

It says (see below). The same happens in a different computer with a fresh Anaconda installation:

ImportError Traceback (most recent call last) File /opt/anaconda3/lib/python3.9/site-packages/gym/envs/classic_control/rendering.py:25, in 24 try: —> 25 from pyglet.gl import * 26 except ImportError as e:

File /opt/anaconda3/lib/python3.9/site-packages/pyglet/gl/init.py:95, in 36 “”“OpenGL and GLU interface. 37 38 This package imports all OpenGL, GLU and registered OpenGL extension (…) 92 below. 93 “”” —> 95 from pyglet.gl.lib import GLException 96 from pyglet.gl.gl import *

File /opt/anaconda3/lib/python3.9/site-packages/pyglet/gl/lib.py:147, in 146 elif pyglet.compat_platform == ‘darwin’: → 147 from pyglet.gl.lib_agl import link_GL, link_GLU, link_AGL 148 else:

File /opt/anaconda3/lib/python3.9/site-packages/pyglet/gl/lib_agl.py:43, in 41 all = [‘link_GL’, ‘link_GLU’, ‘link_AGL’] —> 43 gl_lib = pyglet.lib.load_library(framework=‘/System/Library/Frameworks/OpenGL.framework’) 44 agl_lib = pyglet.lib.load_library(framework=‘/System/Library/Frameworks/AGL.framework’)

File /opt/anaconda3/lib/python3.9/site-packages/pyglet/lib.py:124, in LibraryLoader.load_library(self, *names, **kwargs) 123 if ‘framework’ in kwargs and self.platform == ‘darwin’: → 124 return self.load_framework(kwargs[‘framework’]) 126 if not names:

File /opt/anaconda3/lib/python3.9/site-packages/pyglet/lib.py:279, in MachOLibraryLoader.load_framework(self, path) 277 return lib → 279 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:

ImportError Traceback (most recent call last) Input In [4], in <cell line: 1>() ----> 1 env.render(mode = “human”)

File /opt/anaconda3/lib/python3.9/site-packages/gym/core.py:240, in Wrapper.render(self, mode, **kwargs) 239 def render(self, mode=‘human’, **kwargs): → 240 return self.env.render(mode, **kwargs)

File /opt/anaconda3/lib/python3.9/site-packages/gym/envs/classic_control/mountain_car.py:126, in MountainCarEnv.render(self, mode) 123 carheight = 20 125 if self.viewer is None: → 126 from gym.envs.classic_control import rendering 127 self.viewer = rendering.Viewer(screen_width, screen_height) 128 xs = np.linspace(self.min_position, self.max_position, 100)

File /opt/anaconda3/lib/python3.9/site-packages/gym/envs/classic_control/rendering.py:27, in 25 from pyglet.gl import * 26 except ImportError as e: —> 27 raise ImportError(‘’’ 28 Error occurred while running from pyglet.gl import

  • 29 HINT: make sure you have OpenGL install. On Ubuntu, you can run ‘apt-get install python-opengl’. 30 If you’re running on a server, you may need a virtual frame buffer; something like this should work: 31 ‘xvfb-run -s "-screen 0 1400x900x24" python <your_script.py>’ 32 ‘’') 34 import math 35 import numpy as np

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>’

Unagi
  • 51
  • 1
  • 5
  • 1
    did you read this message? Did you see last part about OpenGL? Did you try to use suggestions in this part? – furas Sep 16 '22 at 23:22
  • Thanks for the response. I looked into that. The problem is that anyone can run Jupyter and run any OpenAI code, for example Lunar Lander, the pole, etc. And nobody must install OpenGL. In Mac I´d need to install XCode, and it takes a LOT of space :( And anyone I´ve met has installed XCode. There should be another way. If you know any other, I´d really appreciate it. – Unagi Sep 17 '22 at 03:56
  • I don't use Mac but why do you have to install XCode to have OpenGL? You don't need it to write code but only to run it. It should be some (precompiler) library with OpenGL. And code need OpenGL then you have to install OpenGL. – furas Sep 17 '22 at 04:10
  • maybe other people doesn't have to install OpenGL because they already have installed OpenGL. I use Linux and I didn't have to install OpenGL because I have it from the beginning - it was installed with system. – furas Sep 17 '22 at 04:11
  • 1
    I check in Google text from your error `Can’t find framework /System/Library/Frameworks/OpenGL.framework.` and first result is [python - ImportError: Can't find framework /System/Library/Frameworks/OpenGL.framework - Stack Overflow](https://stackoverflow.com/questions/65173684/importerror-cant-find-framework-system-library-frameworks-opengl-framework). And on right side you have also `Linked` and `Related` with links to similar questions on Stackoverflow. – furas Sep 17 '22 at 04:16

1 Answers1

2

After trying many different installations, changes of environments, etc. etc. This finally worked for me, in case someone else has the same problem:

pip install --user --upgrade git+http://github.com/pyglet/pyglet@pyglet-1.5-maintenance

I found it in github.com/pyglet/pyglet/pull/335 in case someone wants to see the context.

Unagi
  • 51
  • 1
  • 5