【Reinforcement Learning】Ubuntu中mujoco210 mujoco_py D4RL安装及错误解决

Ubuntu中mujoco210 mujoco_py D4RL安装及错误解决

本文根据一篇知乎文章链接在此进行配置,记录在配置过程中遇到的一些问题,原文作者的教程很详细,在此对原作者表示感谢~

  1. 直接进行知乎原文的第2.2 有效安装过程(避坑)

2.注意上文中各行代码的作用
原文作者的代码有一点点小问题,我在注释中指出,要注意甄别

**注意/.mujoco是隐藏文件夹,在界面中可以打开显示隐藏文件的开关**
# 下载地址 https://github.com/deepmind/mujoco/releases/tag/2.1.0
cd ~/Downloads/
wget https://github.com/deepmind/mujoco/releases/download/2.1.0/mujoco210-linux-x86_64.tar.gz
mv mujoco210-linux-x86_64.tar.gz mujoco210 #这里相当于重命名
tar -zxvf mujoco210-linux-x86_64.tar.gz #这里有问题 应解压重命名后的文件
mkdir ~/mujoco  #这里应改为 mkdir ~/.mujoco 
cp -r mujoco210 ~/.mujoco #复制到~/.mujoco中 
# 添加环境变量
sudo gedit ~/.bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/.mujoco/mujoco210/bin
export MUJOCO_KEY_PATH=~/.mujoco${MUJOCO_KEY_PATH}
source ~/.bashrc

# 测试
cd ~/.mujoco/mujoco210/bin/
./simulate ../model/humanoid.xml

其余按照原作者的内容进行安装

3.在安装mujoco_py时,我首先遇到作者未出现的报错

anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx:127:21: Cannot assign type 'void (const char *) except * nogil' to 'void (*)(const char *) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to type 'void (const char *) except * nogil'.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/__init__.py", line 2, in <module>
    from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/builder.py", line 504, in <module>
    cymj = load_cython_ext(mujoco_path)
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/builder.py", line 110, in load_cython_ext
    cext_so_path = builder.build()
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/builder.py", line 226, in build
    built_so_file_path = self._build_impl()
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/builder.py", line 296, in _build_impl
    so_file_path = super()._build_impl()
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/builder.py", line 239, in _build_impl
    dist.ext_modules = cythonize([self.extension])
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
    cythonize_one(*args)
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: /home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx
>>> import mujoco_py
Compiling /home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx because it changed.
[1/1] Cythonizing /home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx
performance hint: anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx:67:5: Exception check on 'c_warning_callback' will always require the GIL to be acquired.
Possible solutions:
	1. Declare the function as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
	2. Use an 'int' return type on the function to allow an error code to be returned.
performance hint: anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx:104:5: Exception check on 'c_error_callback' will always require the GIL to be acquired.
Possible solutions:
	1. Declare the function as 'noexcept' if you control the definition and you're sure you don't want the function to raise exceptions.
	2. Use an 'int' return type on the function to allow an error code to be returned.

Error compiling Cython file:
------------------------------------------------------------
...
    See c_warning_callback, which is the C wrapper to the user defined function
    '''
    global py_warning_callback
    global mju_user_warning
    py_warning_callback = warn
    mju_user_warning = c_warning_callback
                       ^
------------------------------------------------------------

anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx:92:23: Cannot assign type 'void (const char *) except * nogil' to 'void (*)(const char *) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to type 'void (const char *) except * nogil'.

Error compiling Cython file:
------------------------------------------------------------
...
    See c_warning_callback, which is the C wrapper to the user defined function
    '''
    global py_error_callback
    global mju_user_error
    py_error_callback = err_callback
    mju_user_error = c_error_callback
                     ^
------------------------------------------------------------

anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx:127:21: Cannot assign type 'void (const char *) except * nogil' to 'void (*)(const char *) noexcept nogil'. Exception values are incompatible. Suggest adding 'noexcept' to type 'void (const char *) except * nogil'.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/__init__.py", line 2, in <module>
    from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/builder.py", line 504, in <module>
    cymj = load_cython_ext(mujoco_path)
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/builder.py", line 110, in load_cython_ext
    cext_so_path = builder.build()
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/builder.py", line 226, in build
    built_so_file_path = self._build_impl()
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/builder.py", line 296, in _build_impl
    so_file_path = super()._build_impl()
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/builder.py", line 239, in _build_impl
    dist.ext_modules = cythonize([self.extension])
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/Cython/Build/Dependencies.py", line 1154, in cythonize
    cythonize_one(*args)
  File "/home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/Cython/Build/Dependencies.py", line 1321, in cythonize_one
    raise CompileError(None, pyx_file)
Cython.Compiler.Errors.CompileError: /home/yangsen/anaconda3/envs/myRL/lib/python3.9/site-packages/mujoco_py/cymj.pyx

解决方法:更换Cython版本
参考文章

cpp 复制代码
pip install Cython==3.0.0a10

更换版本后继续 import mojoco_py出现知乎文章中提及的问题,按照原文作者的方法可以解决

4.祝安装成功!

相关推荐
JunLan~1 小时前
Rocky Linux 系统安装/部署 Docker
linux·docker·容器
方竞2 小时前
Linux空口抓包方法
linux·空口抓包
sun0077003 小时前
ubuntu dpkg 删除安装包
运维·服务器·ubuntu
海岛日记3 小时前
centos一键卸载docker脚本
linux·docker·centos
AttackingLin4 小时前
2024强网杯--babyheap house of apple2解法
linux·开发语言·python
shuangrenlong5 小时前
slice介绍slice查看器
java·ubuntu
学Linux的语莫5 小时前
Ansible使用简介和基础使用
linux·运维·服务器·nginx·云计算·ansible
踏雪Vernon5 小时前
[OpenHarmony5.0][Docker][环境]OpenHarmony5.0 Docker编译环境镜像下载以及使用方式
linux·docker·容器·harmonyos
学Linux的语莫5 小时前
搭建服务器VPN,Linux客户端连接WireGuard,Windows客户端连接WireGuard
linux·运维·服务器