Search code examples
pythonpipvirtual-machinegoogle-compute-engineopenai-gym

OpenAI Gym - AttributeError: module 'contextlib' has no attribute 'nullcontext'


I'm running into this error when trying to run a command from docker a docker container on google compute engine.

Here's the stacktrace:

Traceback (most recent call last):
  File "train.py", line 16, in <module>
    from stable_baselines.ppo1 import PPO1
  File "/home/selfplay/.local/lib/python3.6/site-packages/stable_baselines/__init__.py", line 3, in <module>
    from stable_baselines.a2c import A2C
  File "/home/selfplay/.local/lib/python3.6/site-packages/stable_baselines/a2c/__init__.py", line 1, in <module>
    from stable_baselines.a2c.a2c import A2C
  File "/home/selfplay/.local/lib/python3.6/site-packages/stable_baselines/a2c/a2c.py", line 3, in <module>
    import gym
  File "/home/selfplay/.local/lib/python3.6/site-packages/gym/__init__.py", line 13, in <module>
    from gym.envs import make, spec, register
  File "/home/selfplay/.local/lib/python3.6/site-packages/gym/envs/__init__.py", line 10, in <module>
    _load_env_plugins()
  File "/home/selfplay/.local/lib/python3.6/site-packages/gym/envs/registration.py", line 269, in load_env_plugins
    context = contextlib.nullcontext()
AttributeError: module 'contextlib' has no attribute 'nullcontext'

Solution

  • It seems like this is an issue with python 3.6 and gym. Upgrading my container to python 3.7 fixed the issue.