Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: Library "GLU" not found

Tags:

python-3.x

On CentOS 7.5 system, run python3 and execute the following code:

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)

Report the following error after executing the above code:

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 *`

The original exception was:

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

According to the error prompt, after installing OpenGL, the running code will still report the same error. The following is the process of installing 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 ~]#
like image 599
Jackon Avatar asked May 21 '18 10:05

Jackon


3 Answers

For whoever stumbles on this question the solution is to install freeglut-devel package for your OS distribution:

# apt systems - Ubuntu, Debian
apt install freeglut-devel
# yum - Centos
yum -y install freeglut-devel
like image 186
Granitosaurus Avatar answered Nov 16 '22 15:11

Granitosaurus


For raspberry pi zero with Linux DietPi 4.19.97+ #1294 armv6l GNU/Linux:

sudo apt-get install freeglut3-dev

like image 44
Dragos Vasile Avatar answered Nov 16 '22 15:11

Dragos Vasile


Note: To someone who comes wandering in and can't find a solution on Linux. First, install the following:

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

Secondly, if you're using PyCharm flatpak don't use that. Download directly from the website. For some reason executing python programs from the flatpak version fails to find the relevant OpenGL libraries (As mentioned here)

like image 32
Rafay Khan Avatar answered Nov 16 '22 15:11

Rafay Khan