How to resolve seg fault on ‘CarRacing-v0’ environment in OpenAI gym

The problem

When reset()-ing the CarRacing-v0 environment in OpenAI gym as follows:

import gym
env = gym.make('CarRacing-v0')
env.reset()

I get a seg fault:

Track generation: 1043..1308 -> 265-tiles track
/usr/bin/python3: Relink `/lib/x86_64-linux-gnu/libbsd.so.0' with `/lib/x86_64-linux-gnu/librt.so.1' for IFUNC symbol `clock_gettime'
Segmentation fault (core dumped)

My debugging process

  • I thought the issue might be with my machine, because I was having some weird problems with my system clock earlier today. So I tried running the same command in a docker container built from the same docker image on a different machine, and got the same seg fault. So I don’t think it is a problem with my machine.
  • I tried instantiating and reset()-ing a couple of other environments, some within the Box2d package and some outside of it. Specifically, I tried LunarLander-v2 (within Box2d), Bipedal-Walker-v2 (within), and CartPole-v0, (outside Box2d) . All worked like a charm (on both my machine and the other machine).
  • At this point I suspect it might be a bug in the package corresponding to the particular way in which I installed the dependencies for the library.

Other helpful context that may or may not be relevant

  • I’m running my code inside a Docker container
  • OpenAI gym environments tend to have external dependencies to install to get them working. In the case of this environment, I had to install the Box2d package and the python-opengl package. Here is all the relevant code to replicate my installation, from my Dockerfile:
    FROM ubuntu

    RUN 
      apt-get update -y && 
      apt-get install -y 
      python-opengl 
      python3 
      python3-dev 
      python3-pip 
      python3-virtualenv 
      && rm -rf /var/lib/apt/lists/*

    RUN pip3 install --upgrade pip
    RUN pip3 --no-cache-dir install 
        gym 
        box2d-py

What might be causing this seg fault? Is it an issue with my installation? Or could it be a bug in the package?

Update

Actually, the other Box2d environments do NOT work like a charm. They work fine in IPython, but when I exit IPython after running the corresponding code, I get a seg fault. CartPole-v0 (outside Box2d), however, is free of this issue.

Source: StackOverflow