openai / gym

A toolkit for developing and comparing reinforcement learning algorithms.
https://www.gymlibrary.dev
Other
34.61k stars 8.6k forks source link

[Bug Report] Env render flickering on WSL #2421

Closed BUCKFAE closed 3 years ago

BUCKFAE commented 3 years ago

I can't get gym work on WSL2 Windows 11.

Minimal example

import gym

env = gym.make('CartPole-v0')
env.reset()
for _ in range(1000):
    env.render()
    env.step(env.action_space.sample()) # take a random action
    env.close()

When i execute the code it opens a window, displays one frame of the env, closes the window and opens another window in another location of my monitor. Most of the time the content of the window is just black, however sometimes it displays the environment correctly. In both cases the window instantly closes itself and opens the next frame somewhere else.

Troubleshooting i did

Xeyes

Running xeyes works just fine and as expected

Pygame

I installed pygame and wrote a minimal example to see if that works

import pygame

pygame.init()
screen = pygame.display.set_mode((400, 300))
done = False

while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        pygame.draw.rect(screen, (0, 128, 255), pygame.Rect(30, 30, 60, 60))
        pygame.display.flip()

This opens, after a few seconds, a window that displays a recangle - just as expected

Matplotlib

I installed VcXsrv as suggested here and ran a minimal example which worked just as expected as well. Without VcXsrv i had no output yet the script kept running.

import matplotlib.pyplot as plt

x = [i for i in range(20)]
y = [i ** 2 for i in range(20)]

plt.plot(x, y)
plt.show()

System config

Windows version

Windows 11 - Version 21H2 (Build 22000.194)

WSL Status

wsl --status
Standard Distribution: Ubuntu
Standardversion: 2

Das Windows-Subsystem für Linux wurde zuletzt aktualisiert am 23/09/2021
Der Windows-Subsystem für Linux-Kernel kann mit „wsl --update“ manuell aktualisiert werden. Aufgrund Ihrer Systemeinstellungen können jedoch keine automatischen Updates durchgeführt werden.
Um automatischen Kernel-Updates zu erhalten, aktivieren Sie die Windows Update-Einstellung: „Empfangen von Updates für andere Microsoft-Produkte, wenn Windows aktualisiert wird“.
Weitere Informationen finden Sie unter https://aka.ms/wsl2kernel.

Kernel-Version: 5.10.43

Pip Freeze

buckfae-wsl@buckfae-pc:~$ pip freeze
absl-py==0.14.0
astunparse==1.6.3
attrs==19.3.0
Automat==0.8.0
blinker==1.4
cachetools==4.2.2
certifi==2019.11.28
cffi==1.14.6
chardet==3.0.4
clang==5.0
Click==7.0
cloud-init==20.1
cloudpickle==2.0.0
colorama==0.4.3
command-not-found==0.3
configobj==5.0.6
constantly==15.1.0
cryptography==2.8
cycler==0.10.0
Cython==0.29.24
dbus-python==1.2.16
distro==1.4.0
distro-info===0.23ubuntu1
entrypoints==0.3
flatbuffers==1.12
gast==0.4.0
glfw==2.2.0
google-auth==1.35.0
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.40.0
gym==0.20.0
h5py==3.1.0
httplib2==0.14.0
hyperlink==19.0.0
idna==2.8
imageio==2.9.0
importlib-metadata==1.5.0
incremental==16.10.1
Jinja2==2.10.1
jsonpatch==1.22
jsonpointer==2.0
jsonschema==3.2.0
keras==2.6.0
Keras-Preprocessing==1.1.2
keyring==18.0.1
kiwisolver==1.3.2
language-selector==0.1
launchpadlib==1.10.13
lazr.restfulclient==0.14.2
lazr.uri==1.0.3
lockfile==0.12.2
Markdown==3.3.4
MarkupSafe==1.1.0
matplotlib==3.4.3
more-itertools==4.2.0
netifaces==0.10.4
numpy==1.19.5
oauthlib==3.1.0
opt-einsum==3.3.0
Pillow==8.3.2
protobuf==3.18.0
pyasn1==0.4.2
pyasn1-modules==0.2.1
pycparser==2.20
pyglet==1.5.21
PyGObject==3.36.0
PyHamcrest==1.9.0
PyJWT==1.7.1
pymacaroons==0.13.0
PyNaCl==1.3.0
pyOpenSSL==19.0.0
pyparsing==2.4.7
pyrsistent==0.15.5
pyserial==3.4
python-apt==2.0.0
python-dateutil==2.8.2
python-debian===0.1.36ubuntu1
PyYAML==5.3.1
requests==2.22.0
requests-oauthlib==1.3.0
requests-unixsocket==0.2.0
rsa==4.7.2
SecretStorage==2.3.1
service-identity==18.1.0
simplejson==3.16.0
six==1.15.0
ssh-import-id==5.10
systemd-python==234
tensorboard==2.6.0
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.0
tensorflow-estimator==2.6.0
tensorflow-gpu==2.6.0
termcolor==1.1.0
Twisted==18.9.0
typing-extensions==3.7.4.3
ubuntu-advantage-tools==20.3
ufw==0.36
unattended-upgrades==0.1
urllib3==1.25.8
wadllib==1.3.3
Werkzeug==2.0.1
wrapt==1.12.1
zipp==1.0.0
zope.interface==4.7.1

TLDR

OpenAI Gym window flickers like crazy on WSL2.

jkterry1 commented 3 years ago

A few comments: -Gym officially does not support windows -This is a problem with Pyglet that those environments use for rendering, not with gym itself

jkterry1 commented 3 years ago

From the readme:

"We support Python 3.6, 3.7, 3.8 and 3.9 on Linux and macOS. We will accept PRs related to Windows, but do not officially support it."

jkterry1 commented 3 years ago

We're already planning to replace pyglet (there's another issue on this) so I'm going to close this issue given that and the above