[英]How to create and use a custom OpenAI gym environment on google colab?
I have succeeded in creating a custom OpenAI gym environment on my computer following this tutorial: https://web.archive.org/web/20181128171840/https://medium.com/@apoddar573/making-your-own-custom-environment-in-gym-c3b65ff8cdaa按照本教程,我已成功在我的计算机上创建自定义 OpenAI 健身房环境: https ://web.archive.org/web/20181128171840/https://medium.com/@apoddar573/making-your-own-custom- 环境在健身房-c3b65ff8cdaa
Then I've uploaded my package to colab as a zip file and installed it:然后我将我的包作为 zip 文件上传到 colab 并安装它:
!unzip /content/gym-foo.zip
!pip install -e /content/gym-foo
After that I've tried using my custom environment:之后我尝试使用我的自定义环境:
import gym
import gym_foo
gym.make("gym_foo-v0")
This actually works on my computer, but on google colab it gives me:这实际上适用于我的计算机,但在 google colab 上它给了我:
ModuleNotFoundError: No module named 'gym_foo'
Whats going on?这是怎么回事? How can I use my custom environment on google colab?
如何在 google colab 上使用我的自定义环境?
I think you just need to restart your runtime. 我认为您只需要重新启动运行时即可。 It should work after that.
在那之后它应该工作。 I usually have the following at the top of my notebook.
我通常在笔记本顶部有以下内容。 I run the following, whenever I made a change in my environment code to update the version on colab.
每当我更改环境代码以更新colab上的版本时,我都会运行以下命令。
%%capture
!rm -r Foo_env
!git clone https://github.com/username/Foo_env.git
!pip install -e Foo_env
I then restart my runtime through running the following block. 然后,我通过运行以下块重新启动运行时。
import os
def restart_runtime():
os.kill(os.getpid(), 9)
restart_runtime()
You'll get a warning that the environment quite unexpectedly, or something similar, but that's fine. 您会收到一个警告,提示环境相当出乎意料或类似,但这很好。 Now the notebook has the newest version of my repo downloaded and installed.
现在,笔记本电脑已下载并安装了我的回购协议的最新版本。 Using a simple
import gym_foo
should work now. 现在,使用简单的
import gym_foo
应该可以使用。
I'm doing the following steps on colab: 我正在对colab执行以下步骤:
I got the error: 我得到了错误:
UnregisteredEnv: No registered env with id: forex1-v0
UnregisteredEnv:未注册ID为:forex1-v0的env
Note: same steps work with no error when I run them on a local computer. 注意:在本地计算机上运行相同步骤时,它们不会出现任何错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.