OpenAI Gym – AttributeError: module ‘contextlib’ has no attribute ‘nullcontext’

I’m running into this error when trying to run training on my StableBaselines Gym Environment from a virtual machine on Google Compute Engine. I can’t seem to find the issue, I’ve tried upgrading to the most recent versions for all of my libraries but it didn’t seem to fix the issue. Does anyone have any idea what this could be? Thanks!

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'

Source: Python Questions

LEAVE A COMMENT