简体   繁体   English

如何在 google colab 上创建和使用自定义 OpenAI 健身房环境?

[英]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执行以下步骤:

  1. !git clone https://github.com/crilazar/gym_forex1.git !git克隆https://github.com/crilazar/gym_forex1.git
  2. !pip install -e gym_forex1 !pip install -e Gym_forex1
  3. import gym 进口体育馆
  4. import gym_forex1 导入Gym_forex1
  5. env = gym.make('forex1-v0') env = gym.make('forex1-v0')

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.

相关问题 Google Colab 无法加载 OpenAI Gym 环境 - OpenAI Gym environment cannot be loaded in Google Colab 如何使用具有 Openai 稳定基线 RL 算法的自定义 Openai 健身房环境? - How to use a custom Openai gym environment with Openai stable-baselines RL algorithms? 您如何在 Ray Tune 中的自定义 Gym 环境中使用 OpenAI Gym“包装器”? - How do you use OpenAI Gym 'wrappers' with a custom Gym environment in Ray Tune? 如何在没有互联网连接的服务器上安装自定义 OpenAI Gym 环境 - How to install a custom OpenAI Gym environment on a server with no internet connection 创建并安装自己的 OpenAI Gym 环境 - Create and Install own OpenAI Gym Environment 为什么在创建自定义环境时使用 OpenAI Gym 的 Env class 而不是什么都不使用? - Why use Env class from OpenAI Gym as opposed to nothing when creating a custom environment? 导入环境OpenAI Gym报错 - Error in importing environment OpenAI Gym Google Colaboratory 中的 openAI Gym NameError - openAI Gym NameError in Google Colaboratory OpenAI Gym-如何创建一个热点观察空间? - OpenAI Gym - How to create one-hot observation space? 如何创建具有多种功能的 OpenAI Gym Observation 空间 - how to create an OpenAI Gym Observation space with multiple features
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM