ImportError: sys.meta_path is None, Python is likely shutting down in Python OpenAI CartPole

ImportError: sys.meta_path is None, Python is likely shutting down in Python OpenAI CartPole

我刚刚开始学习 OpenAI。我写了我的第一个 OpenAI 代码,我想制作 CartPole AI。但是发生了一些事情。这是我的代码

import gym

# Environment
env = gym.make('CartPole-v0')

# Obsevation
obs = env.reset()

for _ in range(100):
    env.render()

    cart_pos,cart_vel,ang,ang_vel = obs

    if ang > 0:
        action = 1
    else:
        action = 0

    obs,reward,done,info = env.step(action)

当我运行代码时,会打印一条警告

(base) F:\Python Scripts\CartPole-OpenAI>python CartPole.py
C:\Users\PHILIP\Anaconda3\lib\site-packages\gym\logger.py:30: UserWarning: [33mWARN: You are calling 'step()' even though this environment has already returned done = True. You should always call 'reset()' once you receive 'done = True' -- any further steps are undefined behavior.[0m
  warnings.warn(colorize('%s: %s'%('WARN', msg % args), 'yellow'))

循环完成后

Exception ignored in: <function Viewer.__del__ at 0x00000209A1788048>
Traceback (most recent call last):
  File "C:\Users\PHILIP\Anaconda3\lib\site-packages\gym\envs\classic_control\rendering.py", line 162, in __del__
  File "C:\Users\PHILIP\Anaconda3\lib\site-packages\gym\envs\classic_control\rendering.py", line 81, in close
  File "C:\Users\PHILIP\Anaconda3\lib\site-packages\pyglet\window\win32\__init__.py", line 299, in close
  File "C:\Users\PHILIP\Anaconda3\lib\site-packages\pyglet\window\__init__.py", line 820, in close
ImportError: sys.meta_path is None, Python is likely shutting down

感谢您的帮助。谢谢

尝试添加

env.close()

env.env.close()

到脚本的最末端