20

Try to run a test code for stable baselines gym

import gym

from stable_baselines3 import A2C

env = gym.make("CartPole-v1")

model = A2C("MlpPolicy", env, verbose=1)
model.learn(total_timesteps=10_000)

obs = env.reset()
for i in range(100):
    action, _state = model.predict(obs, deterministic=True)
    obs, reward, done, info = env.step(action)
    env.render()
    if done:
      obs = env.reset()

found the error "NameError: name 'glPushMatrix' is not defined"

Traceback (most recent call last):
  File "test_cart_pole.py", line 14, in <module>
    env.render()
  File "/Users/xxx/opt/anaconda3/lib/python3.8/site-packages/gym/core.py", line 295, in render
    return self.env.render(mode, **kwargs)
  File "/Users/xxx/opt/anaconda3/lib/python3.8/site-packages/gym/envs/classic_control/cartpole.py", line 229, in render
    return self.viewer.render(return_rgb_array=mode == "rgb_array")
  File "/Users/xxx/opt/anaconda3/lib/python3.8/site-packages/gym/envs/classic_control/rendering.py", line 126, in render
    self.transform.enable()
  File "/Users/xxx/opt/anaconda3/lib/python3.8/site-packages/gym/envs/classic_control/rendering.py", line 232, in enable
    glPushMatrix()
NameError: name 'glPushMatrix' is not defined

I tried "pip install PyOpenGL PyOpenGL_accelerate", which didn't help also uninstall pyglet and install again , did't work too Any Idea???

1
  • Which version of gym are you using? I think that if you install the latest one 0.26.2 the error will disappear, but your code will not be working with the latest gym. So pfaya has the right solution if you want the quickest way to get this fixed.
    – SimAzz
    Commented Nov 30, 2022 at 17:52

1 Answer 1

45

Just had the same problem. Fixed it by installing an older version of pyglet:

$ pip install pyglet==1.5.27

I don't know if this is the latest version that avoids the problem, but it works.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.