MuJoCo 是目前机器人强化学习中最流行的仿真器之一
MuJoCo官网:http://mujoco.org/
登陆官网获取许可证:https://www.roboti.us/license.html
getid_osx
./getid_osx
打开Permission denied
chmod -x getid_osx
Permission denied
chmod -f 711 getid_osx
LICENSE.txt
和mjkey.txt
Linux 请选择:
https://www.roboti.us/download/mujoco200_linux.zip
OS 系统请选择:
https://www.roboti.us/download/mujoco200_macos.zip
注意,这里的目录设置很重要!如果搞不清楚的话,请选择默认安装路径,以免出错!
mkdir ~/.mujoco
创建安装目录mv mujoco200_macos ~/.mujoco/mujoco200
mv mjkey.txt ~/.mujoco/mjkey.txt
,多拷贝一份到~/.mujoco/mujoco200/bin
,否则后面测试可能出问题这里开始出现大量的坑啊~~~
官方文档介绍直接使用 pip3 install -U 'mujoco-py<2.1,>=2.0'
即可,但是运行后:
ERROR: Failed building wheel for mujoco-py
Failed to build mujoco-py
ERROR: Could not build wheels for mujoco-py which use PEP 517 and cannot be installed directly
pip install --no-use-pep517 'mujoco-py<2.1,>=2.0'
试了下不行~~~
pip install mujoco_py==2.0.2.8
安装成功,这个方案是安装了一个旧版本的 mujoco_py
import mujoco_py
import os
mj_path, _ = mujoco_py.utils.discover_mujoco()
xml_path = os.path.join(mj_path, 'model', 'humanoid.xml')
model = mujoco_py.load_model_from_path(xml_path)
sim = mujoco_py.MjSim(model)
print(sim.data.qpos)
# [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
sim.step()
print(sim.data.qpos)
# [-2.09531783e-19 2.72130735e-05 6.14480786e-22 -3.45474715e-06
# 7.42993721e-06 -1.40711141e-04 -3.04253586e-04 -2.07559344e-04
# 8.50646247e-05 -3.45474715e-06 7.42993721e-06 -1.40711141e-04
# -3.04253586e-04 -2.07559344e-04 -8.50646247e-05 1.11317030e-04
# -7.03465386e-05 -2.22862221e-05 -1.11317030e-04 7.03465386e-05
# -2.22862221e-05]
RuntimeError: Could not find GCC executable.
HINT: On OS X, install GCC with `brew install gcc`. or `port install gcc`.
貌似是缺少了 gcc
brew install gcc
结果发现:
Warning: gcc 9.3.0_1 is already installed and up-to-date
看来我已经装了,但是程序没有找到
/Library/Developer/CommandLineTools/SDKs
发现以下 3 个文件夹
首先,把 MacOSX.sdk 改成 MacOSX_orig.sdk
然后,右键点击 MacOSX10.14.sdk,选择复制
然后,该目录下面出现个副本,把该副本改名为 MacOSX.sdk
形成以下目录:
很遗憾,报错依然存在~~~
brew uninstall gcc@9
brew uninstall gcc
brew install gcc@8
就是用老版本的 gcc,原因嘛我估计是前面安装了旧版本的mujoco_py,所以不识别 gcc 9
aise CompileError(msg)
distutils.errors.CompileError: command '/usr/local/bin/gcc-8' failed with exit status 1
貌似是编译错误
c_compilers = ['/usr/local/bin/gcc-6',
'/usr/local/bin/gcc-7',
'/usr/local/bin/gcc-8',
'/usr/local/bin/gcc-9', # 添加这一句
'/opt/local/bin/gcc-mp-6',
于是重新安装 gcc
brew install gcc
这次可以找到 gcc 9 了,但是依然报错:
raise CompileError(msg)
distutils.errors.CompileError: command '/usr/local/bin/gcc-9' failed with exit status 1
还是编译错误
brew install llvm
open -e .bash_profile
export PATH="/usr/local/opt/llvm/bin:$PATH"
export CC="/usr/local/opt/llvm/bin/clang"
export CXX="/usr/local/opt/llvm/bin/clang++"
export CXX11="/usr/local/opt/llvm/bin/clang++"
export CXX14="/usr/local/opt/llvm/bin/clang++"
export CXX17="/usr/local/opt/llvm/bin/clang++"
export CXX1X="/usr/local/opt/llvm/bin/clang++"
export LDFLAGS="-L/usr/local/opt/llvm/lib"
export CPPFLAGS="-I/usr/local/opt/llvm/include"
然后终端里面:
source .bash_profile
很遗憾~~~ 报错继续~~~
修改系统偏好里面的“安全性与隐私”:
在 “开发者工具” 里面把 “终端” 打勾
打开终端
pip install -U 'mujoco-py<2.1,>=2.0'
成功:
Successfully installed mujoco-py-2.0.2.11
在 PyCharm 中运行测试代码,依然报错,考虑了下应该还是权限问题,改用了终端里面的 python3 运行,成功!
在 PyCharm 里面运行的时候,会跳出无法验证开发者的提示,点击“问号”,会提示跳转到“安全性与隐私”中,点击允许。
重新运行,如果还有跳出,再点击允许。
多允许几次,直到没有跳出提示,运行成功!
PS: 每个人的系统环境都有所差别,所以如果不成功,可以挑选上面的各种解决方案进行尝试,如果还有问题,也欢迎留言探讨!