在使用openai的强化学习库gym时,出现了如下错误:
Traceback (most recent call last):
File "/Users/anaconda3/lib/python3.6/site-packages/gym/envs/classic_control/rendering.py", line 347, in __del__
File "/Users/anaconda3/lib/python3.6/site-packages/gym/envs/classic_control/rendering.py", line 343, in close
File "/Users/anaconda3/lib/python3.6/site-packages/pyglet/window/cocoa/__init__.py", line 281, in close
File "/Users/anaconda3/lib/python3.6/site-packages/pyglet/window/__init__.py", line 770, in close
ImportError: sys.meta_path is None, Python is likely shutting down
解决方式如下:
1. 在创建并使用env之后,在代码最后使用env.env.close()注意:要使用两层env来解决这个问题(怀疑是环境本身存在继承)
2.在创建env之后,可以增加一句
env = env.unwrapped
我的理解是这个命令可以剥离env的外层包装器,这样之后可以直接使用env.close()解决上述问题
reference gym version:0.13.0