在CentOS 7.5系统上,运行python3并执行以下代码:
import gym
import time
env = gym.make('CartPole-v0')
observation = env.reset()
count = 0
for t in range(100):
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
if done:
break
env.render()
count+=1
time.sleep(0.2)
执行上述代码后报告以下错误:
Traceback (most recent call last):
File "<stdin>", line 6, in <module>
File "/root/gym/gym/core.py", line 284, in render
return self.env.render(mode)
File "/root/gym/gym/envs/classic_control/cartpole.py", line 106, in render
from gym.envs.classic_control import rendering
File "/root/gym/gym/envs/classic_control/rendering.py", line 25, in <module>
reraise(prefix="Error occured while running `from pyglet.gl import *`",suffix="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>'")
File "/root/gym/gym/utils/reraise.py", line 17, in reraise
reraise_impl(e, traceback)
File "/root/gym/gym/utils/reraise_impl_py3.py", line 4, in reraise_impl
raise e.with_traceback(traceback) from None
File "/root/gym/gym/envs/classic_control/rendering.py", line 23, in <module>
from pyglet.gl import *
File "/root/anaconda3/envs/gymlab/lib/python3.6/site-packages/pyglet/gl/__init__.py", line 100, in <module>
from pyglet.gl.lib import GLException
File "/root/anaconda3/envs/gymlab/lib/python3.6/site-packages/pyglet/gl/lib.py", line 143, in <module>
from pyglet.gl.lib_glx import link_GL, link_GLU, link_GLX
File "/root/anaconda3/envs/gymlab/lib/python3.6/site-packages/pyglet/gl/lib_glx.py", line 51, in <module>
glu_lib = pyglet.lib.load_library('GLU')
File "/root/anaconda3/envs/gymlab/lib/python3.6/site-packages/pyglet/lib.py", line 158, in load_library
raise ImportError('Library "%s" not found.' % names[0])
gym.utils.reraise.ReraisedException: Error occured while running `from pyglet.gl import *`
最初的例外是:
ImportError: Library "GLU" not found.
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>'
根据错误提示,安装OpenGL后,正在运行的代码仍会报告相同的错误。以下是安装OpenGL的过程:
[root@devmaster ~]# yum -y install python-opengl
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: ftp.iij.ad.jp
Package PyOpenGL-3.0.1-6.el7.noarch already installed and latest version
Nothing to do
[root@devmaster ~]#
答案 0 :(得分:4)
对于偶然发现此问题的人,解决方案是为您的OS发行版安装freeglut-devel
软件包:
# apt systems - Ubuntu, Debian
apt install freeglut-devel
# yum - Centos
yum -y install freeglut-devel
答案 1 :(得分:2)
对于使用Linux DietPi 4.19.97+#1294 armv6l GNU / Linux的树莓派零:
sudo apt-get install freeglut3-dev