'gnwrapper.Animation(gym.make('CartPole-v1')) doesn't work
I'm trying to run this code (found here):
import gnwrapper
import gym
env = gnwrapper.Animation(gym.make('CartPole-v1'))
obs = env.reset()
for _ in range(1000):
next_obs, reward, done, info = env.step(env.action_space.sample())
env.render()
obs = next_obs
if done:
obs = env.reset()
And I have the following error:
Traceback (most recent call last):
File "C:\Users\lhott\Documents\Formation scolaire\These\Formations\RL\DRL\main.py", line 4, in <module>
env = gnwrapper.Animation(gym.make('CartPole-v0'))
File "C:\Users\lhott\AppData\Local\Programs\Python\Python310\lib\site-packages\gnwrapper\__init__.py", line 86, in __init__
super().__init__(env,size)
File "C:\Users\lhott\AppData\Local\Programs\Python\Python310\lib\site-packages\gnwrapper\__init__.py", line 62, in __init__
self._display = _VirtualDisplaySingleton(size)
File "C:\Users\lhott\AppData\Local\Programs\Python\Python310\lib\site-packages\gnwrapper\__init__.py", line 36, in __init__
self._display = Display(visible=0,size=self.size)
File "C:\Users\lhott\AppData\Local\Programs\Python\Python310\lib\site-packages\pyvirtualdisplay\display.py", line 54, in __init__
self._obj = cls(
File "C:\Users\lhott\AppData\Local\Programs\Python\Python310\lib\site-packages\pyvirtualdisplay\xvfb.py", line 44, in __init__
AbstractDisplay.__init__(
File "C:\Users\lhott\AppData\Local\Programs\Python\Python310\lib\site-packages\pyvirtualdisplay\abstractdisplay.py", line 85, in __init__
helptext = get_helptext(program)
File "C:\Users\lhott\AppData\Local\Programs\Python\Python310\lib\site-packages\pyvirtualdisplay\util.py", line 13, in get_helptext
p = subprocess.Popen(
File "C:\Users\lhott\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\lhott\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
Process finished with exit code 1
I'm using Python 3.10.2 and jupyterlab and I also have tried replacing 'CartPole-v1' by 'CartPole-v0' but still have no idea what is happening.
EDIT: I should add I'm using Windows 11 and reading the requirement section, I'm a bit confused as to what I should do (does it not work on Windows). Here is the requirement section of the link I provided:
- Requirement
Linux
Xvfb (for Gym)
On Ubuntu, you can install sudo apt update && sudo apt install xvfb.
Open GL (for some environment)
On Ubuntu, you can install sudo apt update && sudo apt install python3-opengl
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
