当前位置:   article > 正文

ubuntu20.04安装Gym_ubuntu 安装openaigym

ubuntu 安装openaigym

按照官网Gym指导安装Gym,输入以下代码

pip install gym

成功安装gym0.21.0,输入下面代码克隆gym在github的库

git clone https://github.com/openai/gym

出现错误

  1. (RL) johnwatson@rescuer-r720:~$ git clone https://github.com/openai/gym
  2. 正克隆到 'gym'...
  3. fatal: 无法访问 'https://github.com/openai/gym/':GnuTLS recv error (-110): The TLS connection was non-properly terminated.

将代码更改为

git clone git://github.com/openai/gym

成功克隆。

运行代码来添加环境

  1. cd gym
  2. pip install -e .

出现问题

  1. (RL) johnwatson@rescuer-r720:~/gym$ pip install -e .
  2. Obtaining file:///home/johnwatson/gym
  3. Installing build dependencies ... done
  4. Getting requirements to build wheel ... done
  5. Preparing wheel metadata ... done
  6. 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)
  7. 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造轮子失败

  1. Building wheel for mujoco-py (setup.py) ... error
  2. ERROR: Command errored out with exit status 1:
  3. 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
  4. cwd: /tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/
  5. Complete output (54 lines):
  6. running bdist_wheel
  7. running build
  8. You appear to be missing MuJoCo. We expected to find the file here: /home/johnwatson/.mujoco/mjpro150
  9. This package only provides python bindings, the library must be installed separately.
  10. Please follow the instructions on the README to install MuJoCo
  11. https://github.com/openai/mujoco-py#install-mujoco
  12. Which can be downloaded from the website
  13. https://www.roboti.us/index.html
  14. Traceback (most recent call last):
  15. File "<string>", line 1, in <module>
  16. File "/tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/setup.py", line 44, in <module>
  17. tests_require=read_requirements_file('requirements.dev.txt'),
  18. File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/site-packages/setuptools/__init__.py", line 153, in setup
  19. return distutils.core.setup(**attrs)
  20. File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/distutils/core.py", line 148, in setup
  21. dist.run_commands()
  22. File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/distutils/dist.py", line 966, in run_commands
  23. self.run_command(cmd)
  24. File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/distutils/dist.py", line 985, in run_command
  25. cmd_obj.run()
  26. File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/site-packages/wheel/bdist_wheel.py", line 299, in run
  27. self.run_command('build')
  28. File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/distutils/cmd.py", line 313, in run_command
  29. self.distribution.run_command(command)
  30. File "/home/johnwatson/anaconda3/envs/PY37RL/lib/python3.7/distutils/dist.py", line 985, in run_command
  31. cmd_obj.run()
  32. File "/tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/setup.py", line 28, in run
  33. import mujoco_py # noqa: force build
  34. File "/tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/mujoco_py/__init__.py", line 3, in <module>
  35. from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
  36. File "/tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/mujoco_py/builder.py", line 502, in <module>
  37. mjpro_path, key_path = discover_mujoco()
  38. File "/tmp/pip-install-stmlc2i5/mujoco-py_ec54c2a403274091be6b50a22020eb73/mujoco_py/utils.py", line 93, in discover_mujoco
  39. raise Exception(message)
  40. Exception:
  41. You appear to be missing MuJoCo. We expected to find the file here: /home/johnwatson/.mujoco/mjpro150
  42. This package only provides python bindings, the library must be installed separately.
  43. Please follow the instructions on the README to install MuJoCo
  44. https://github.com/openai/mujoco-py#install-mujoco
  45. Which can be downloaded from the website
  46. https://www.roboti.us/index.html
  47. ----------------------------------------
  48. ERROR: Failed building wheel for mujoco-py

在网上查询后,发现这篇比较靠谱如何在linux中安装gym[all]_Joney(^_^)的博客-CSDN博客_linux安装gym

按照他的方法进行安装mujoco

下载mujoco到.mujoco目录内

  1. cd ~
  2. mkdir .mujoco
  3. wget https://www.roboti.us/download/mjpro150_linux.zip
  4. unzip mjpro150_linux.zip

 下载license到.mujoco和.mujoco/mjpro150/bin/两个目录下

  1. wget https://www.roboti.us/file/mjkey.txt
  2. cd .mujoco/mjpro150/bin/
  3. 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'

 输入此代码解决

  1. sudo apt-get update -y
  2. sudo apt-get install -y patchelf

 输入代码安装gym的完整版

pip install -e .[all]

安装成功。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/990568
推荐阅读
相关标签
  

闽ICP备14008679号