Python - 用 gym 制作的脚本在 Mac 上不起作用

标签 python deep-learning pycharm reinforcement-learning

我正在学习教程 here学习深度强化学习(我对这个话题很陌生)。

当我尝试在我的 Macbook 上运行下面的脚本时,它返回一个导入错误(ImportError: sys.meta_path is None, Python is likely shutdown)。 我尝试从 Mac 终端和 Pycharm 中运行它,结果相同。 我也尝试了其他深度学习脚本,错误是一样的(它似乎与这个脚本无关)。

你能帮我理解我错在哪里吗?

脚本:

# Import the gym module
import gym

# Create a breakout environment
env = gym.make('BreakoutDeterministic-v4')
# Reset it, returns the starting frame
frame = env.reset()
# Render
env.render()

is_done = False
while not is_done:
  # Perform a random action, returns the new frame, reward and whether the game is over
  frame, reward, is_done, _ = env.step(env.action_space.sample())
  # Render
  env.render()

错误如下:

/usr/local/bin/python3.6 /Users/marcogdepinto/PycharmProjects/PlayPong/pong.py
2018-05-12 18:58:11.915 Python[567:12594] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
Exception ignored in: <bound method SimpleImageViewer.__del__ of <gym.envs.classic_control.rendering.SimpleImageViewer object at 0x10b65bc88>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/gym/envs/classic_control/rendering.py", line 347, in __del__
  File "/usr/local/lib/python3.6/site-packages/gym/envs/classic_control/rendering.py", line 343, in close
  File "/usr/local/lib/python3.6/site-packages/pyglet/window/cocoa/__init__.py", line 281, in close
  File "/usr/local/lib/python3.6/site-packages/pyglet/window/__init__.py", line 770, in close
ImportError: sys.meta_path is None, Python is likely shutting down

Process finished with exit code 0

最佳答案

"Try adding env.close() at the end of your programs, in my scenario, it works nice"

src

关于Python - 用 gym 制作的脚本在 Mac 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50308750/

相关文章:

python - 使用可变键的 Jinja2 字典查找

python - 字典中的递归

python - 我应该如何使用 Keras(和 TensorFlow)编写负二项分布的损失函数?

pycharm 的 Scikit-learn 外部文档 URL?

django - 类' __str__ 的 Python 测试覆盖率

python - 无法在我的 CentOS 6.7 上安装 odoo 9.0

python - 如何在这里进行广义特征分解?

machine-learning - 为什么RL叫 'reinforcement'学习?

machine-learning - 神经网络特征组合学

python-3.x - 让 PyC​​harm 将字符串识别为路径