按照官网Gym指导安装Gym,输入以下代码
pip install gym
成功安装gym0.21.0,输入下面代码克隆gym在github的库
git clone https://github.com/openai/gym
出现错误
(RL) johnwatson@rescuer-r720:~$ git clone https://github.com/openai/gym
正克隆到 'gym'...
fatal: 无法访问 'https://github.com/openai/gym/':GnuTLS recv error (-110): The TLS connection was non-properly terminated.
将代码更改为
git clone git://github.com/openai/gym
成功克隆。
运行代码来添加环境
cd gym
pip install -e .
出现问题
(RL) johnwatson@rescuer-r720:~/gym$ pip install -e .
Obtaining file:///home/johnwatson/gym
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
ERROR: Could not find a version that satisfies the requirement importlib-metadata>=4.10.0; python_version < "3.10" (from gym) (from versions: 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21, 0.22, 0.23, 1.0.0, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.5.1, 1.5.2, 1.6.0, 1.6.1, 1.7.0, 2.0.0, 2.1.0, 2.1.1, 2.1.2, 3.0.0, 3.1.0, 3.1.1, 3.2.0, 3.3.0, 3.4.0, 3.5.0, 3.6.0, 3.7.0, 3.7.1, 3.7.2, 3.7.3, 3.8.0, 3.8.1, 3.8.2, 3.9.0, 3.9.1, 3.10.0, 3.10.1, 4.0.0, 4.0.1, 4.1.0, 4.2.0, 4.3.0, 4.3.1, 4.4.0, 4.5.0, 4.6.0, 4.6.1, 4.6.2, 4.6.3, 4.6.4, 4.7.0, 4.7.1, 4.8.0, 4.8.1, 4.8.2, 4.8.3)
ERROR: No matching distribution found for importlib-metadata>=4.10.0; python_version < "3.10"
错误:不能找到一个合适的版本满足需求(importlib-metadata>=4.10.0;python_version<3.10)
从错误上看程序判定我的importlib-metadata大于4.10,python小于3.10,没有一个合适的gym来满足importlib-metadata,python的版本。
查看了我在RL虚拟环境下的importlib-metadata和python版本
importlib-metadata 4.8.3
python 3.6.13
importlib-metadata不大于4.10,python小于3.10
“错误” 的判断和我查询的不太一样。
在Gym的Github上看到这样一段话:We support Python 3.7, 3.8, 3.9 and 3.10 on Linux and macOS. We will accept PRs related to Windows, but do not officially support it.
说明Gym的最低Python支持版本是3.7。从下面的图可以看到torch1.1.0最高可以匹配python3.7,所以可以将python升级到3.7。
尝试将Python升级到3.7,目的是在linux虚拟环境下升级python到指定版本,转念一想,之前安装CUDA,Pytorch还挺方便的,所以就重新创建一个python3.7的虚拟环境更方便些。
成功安装python3.7的虚拟环境后,重复以上步骤,成功安装gym0.21.0
接下来是安装gym的所有环境,运行以下代码
pip install -e .[all]
从这里出现错误,为mujoco-py造轮子失败
Building wheel for mujoco-py (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /home/johnwatson/anaconda3/envs/PY37RL/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/setup.py'"'"'; __file__='"'"'/tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-7uxcj4bj
cwd: /tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/
Complete output (54 lines):
running bdist_wheel
running build
You appear to be missing MuJoCo. We expected to find the file here: /home/johnwatson/.mujoco/mjpro150
This package only provides python bindings, the library must be installed separately.
Please follow the instructions on the README to install MuJoCo
https://github.com/openai/mujoco-py#install-mujoco
Which can be downloaded from the website
https://www.roboti.us/index.html
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/setup.py", line 44, in <module>
tests_require=read_requirements_file('requirements.dev.txt'),
File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/site-packages/setuptools/__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/distutils/core.py", line 148, in setup
dist.run_commands()
File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/site-packages/wheel/bdist_wheel.py", line 299, in run
self.run_command('build')
File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/setup.py", line 28, in run
import mujoco_py # noqa: force build
File "/tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/mujoco_py/__init__.py", line 3, in <module>
from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
File "/tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/mujoco_py/builder.py", line 502, in <module>
mjpro_path, key_path = discover_mujoco()
File "/tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/mujoco_py/utils.py", line 93, in discover_mujoco
raise Exception(message)
Exception:
You appear to be missing MuJoCo. We expected to find the file here: /home/johnwatson/.mujoco/mjpro150
This package only provides python bindings, the library must be installed separately.
Please follow the instructions on the README to install MuJoCo
https://github.com/openai/mujoco-py#install-mujoco
Which can be downloaded from the website
https://www.roboti.us/index.html
----------------------------------------
ERROR: Failed building wheel for mujoco-py
在网上查询后,发现这篇比较靠谱如何在linux中安装gym[all]_Joney(^_^)的博客-CSDN博客_linux安装gym
按照他的方法进行安装mujoco
下载mujoco到.mujoco目录内
cd ~
mkdir .mujoco
wget https://www.roboti.us/download/mjpro150_linux.zip
unzip mjpro150_linux.zip
下载license到.mujoco和.mujoco/mjpro150/bin/两个目录下
wget https://www.roboti.us/file/mjkey.txt
cd .mujoco/mjpro150/bin/
wget https://www.roboti.us/file/mjkey.txt
打开.bashrc文件
gedit ~/.bashrc
在.bashrc文件中添加下面的代码
LD_LIBRARY_PATH=$HOME/.mujoco/mujoco210/bin pip install mujoco-py
然后source一下
source ~/.bashrc
下载对应的150版本,这段代码要在gym目录下运行才能成功。
wget https://github.com/openai/mujoco-py/archive/refs/tags/1.50.1.0.tar.gz
2022年5月6日
在gym目录下安装依赖包
pip install -r requirements.txt
遇到问题
No such file or directory: 'patchelf': 'patchelf'
输入此代码解决
sudo apt-get update -y
sudo apt-get install -y patchelf
输入代码安装gym的完整版
pip install -e .[all]
安装成功。