AureumChaos / LEAP

A general purpose Library for Evolutionary Algorithms in Python.
Academic Free License v3.0
83 stars 19 forks source link

Can't run Atari examples and Matplotlib at the same time on Arch Linux #79

Open SigmaX opened 4 years ago

SigmaX commented 4 years ago

On the latest Arch Linux, I hit an obscure Qt error if I try and run an OpenAI Gym example after installing the Atari game suite. It seems to be caused by a conflict between Qt and matplotlib.

Steps to Reproduce

  1. Install LEAP in a venv: make venv && source venv/bin/activate && make depend && make setup)
  2. At this point the Cartpole example should run fine: python examples/openai_gym.py evolve
  3. Install the Atari environments: pip install gym[atari]
  4. The Cartpole example will now fail: python examples/openai_gym.py evolve
  5. Running Cartpole without evolution will still work: python examples/openai_gym.py keyboard

Expected Behavior

Both matplotlib and OpenAI gym visualizations should run at the same time in separate windows.

More Info

The error I get is as follows:

$ python examples/openai_gym.py evolve --env SpaceInvaders-ram-v4

...

QObject::moveToThread: Current thread (0x55901bdb9000) is not the object's thread (0x55901c34c6e0).
Cannot move to target thread (0x55901bdb9000)

qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/eric/repos/LEAP/venv/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc.

Aborted (core dumped)

Interestingly, the error is not thrown when the Gym environment tries to run, but rather when we call plt.figure() to set up the visualization probes for the example.

It seems that gym runs something (if and only if [atari] is installed, even if unused) that clashes with Matplotlib: examples that only use Matplotlib or only use gym work fine, but my example that uses both does not.

A possible culprit is OpenCV, which is a dependency of gym[atari] and has been known to cause similar Qt errors in other contexts.

SigmaX commented 4 years ago

I failed to reproduce the issue on an Ubuntu 20.04 VM, so it looks like this is specific to my Arch environment.