首页 > 解决方案 > ImportError: sys.meta_path is None, Python 可能在 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

我感谢您的帮助。谢谢

标签: pythonpython-3.xopenai-gym

解决方案


尝试添加

env.close()

或者

env.env.close()

到剧本的尽头


推荐阅读