在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 ~]#发布于 2018-10-19 12:46:23
对于遇到这个问题的人,解决方案是为您的操作系统发行版安装freeglut-devel包:
# apt systems - Ubuntu, Debian
apt install freeglut-devel
# yum - Centos
yum -y install freeglut-devel发布于 2020-02-26 01:39:27
对于带有Linux DietPi 4.19.97+ #1294 armv6l GNU/Linux的树莓派0:
sudo apt-get install freeglut3-dev
发布于 2021-11-02 18:08:08
注意:对于那些游荡在Linux上找不到解决方案的人来说。首先,安装以下软件:
sudo apt install freeglut3-dev freeglut3 libgl1-mesa-dev libglu1-mesa-dev libxext-dev libxt-dev
sudo apt install python3-opengl libgl1-mesa-glx libglu1-mesa其次,如果您使用的是PyCharm flatpak,请不要使用它。直接从网站下载。由于某种原因,执行flatpak版本中的python程序无法找到相关的OpenGL库(如前面提到的here)。
https://stackoverflow.com/questions/50446867
复制相似问题