davidADSP / SIMPLE

Selfplay In MultiPlayer Environments
GNU General Public License v3.0
308 stars 105 forks source link

AttributeError: module 'contextlib' has no attribute 'nullcontext' #20

Closed jay-tux closed 2 years ago

jay-tux commented 3 years ago

Exactly as the title says. I followed the steps from the README.

> sudo docker-compose exec app python3 test.py -d -g 1 -a base base human -e sushigo 
/home/selfplay/.local/lib/python3.6/site-packages/ale_py/roms/utils.py:90: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
  for external in metadata.entry_points().get(self.group, []):
Traceback (most recent call last):
  File "test.py", line 13, in <module>
    from stable_baselines import logger
  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'

All output:

> sudo docker-compose up -d                                                          
[+] Running 1/1
 ⠿ Container selfplay  Started                                                                                                      0.5s
 > sudo bash ./scripts/install_env.sh sushigo                         
Defaulting to user installation because normal site-packages is not writeable
Obtaining file:///app/environments/sushigo
  Preparing metadata (setup.py) ... done
Requirement already satisfied: gym>=0.9.4 in /home/selfplay/.local/lib/python3.6/site-packages (from sushigo==0.1.0) (0.21.0)
Requirement already satisfied: numpy>=1.13.0 in /home/selfplay/.local/lib/python3.6/site-packages (from sushigo==0.1.0) (1.19.5)
Requirement already satisfied: opencv-python>=3.4.2.0 in /home/selfplay/.local/lib/python3.6/site-packages (from sushigo==0.1.0) (4.5.4.58)
Requirement already satisfied: cloudpickle>=1.2.0 in /home/selfplay/.local/lib/python3.6/site-packages (from gym>=0.9.4->sushigo==0.1.0) (2.0.0)
Requirement already satisfied: importlib-metadata>=4.8.1 in /home/selfplay/.local/lib/python3.6/site-packages (from gym>=0.9.4->sushigo==0.1.0) (4.8.1)
Requirement already satisfied: zipp>=0.5 in /home/selfplay/.local/lib/python3.6/site-packages (from importlib-metadata>=4.8.1->gym>=0.9.4->sushigo==0.1.0) (3.6.0)
Requirement already satisfied: typing-extensions>=3.6.4 in /home/selfplay/.local/lib/python3.6/site-packages (from importlib-metadata>=4.8.1->gym>=0.9.4->sushigo==0.1.0) (3.10.0.2)
Installing collected packages: sushigo
  Running setup.py develop for sushigo
Successfully installed sushigo-0.1.0
> sudo docker-compose exec app python3 test.py -d -g 1 -a base base human -e sushigo 
/home/selfplay/.local/lib/python3.6/site-packages/ale_py/roms/utils.py:90: DeprecationWarning: SelectableGroups dict interface is deprecated. Use select.
  for external in metadata.entry_points().get(self.group, []):
Traceback (most recent call last):
  File "test.py", line 13, in <module>
    from stable_baselines import logger
  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'
Hugosabb commented 3 years ago

Hello, I had the same issue and I found a solution that works for me for the moment ! According to this post https://stackoverflow.com/questions/69520829/openai-gym-attributeerror-module-contextlib-has-no-attribute-nullcontext a solution could be to "Degrading the version of gym [...] from 0.21.0 to 0.15.7." Concretely you can run this command :

I hope it will help you !

jay-tux commented 3 years ago

Awesome! Thank you!

However, I still feel it'd be nice if SIMPLE came out-of-the-box with that setting....

Hugosabb commented 3 years ago

Yes, I agree, this is a recent bug that may be fixed soon. I think the "install_requires" in all setup.py files in each environment folder should be changed to make sure that the gym version is lower than 0.15.7.

fxjordan commented 2 years ago

Yes, I agree, this is a recent bug that may be fixed soon. I think the "install_requires" in all setup.py files in each environment folder should be changed to make sure that the gym version is lower than 0.15.7.

22 does exactly that.

@davidADSP This should be fixes asap. The tutorial does not work at the moment, so new users may quit using/exploring the framework (I nearly did :)