【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.祝安装成功!

相关推荐
林农1 小时前
C05S14-MySQL高级语句
linux·mysql·云计算
Wanliang Li1 小时前
Linux电源管理——CPU Hotplug 流程
linux·嵌入式硬件·嵌入式·armv8·电源管理·cpuhotplug
fnd_LN2 小时前
Linux文件目录 --- mkdir命令,创建目录,多级目录,设置目录权限
linux·运维·服务器
达帮主2 小时前
7.C语言 宏(Macro) 宏定义,宏函数
linux·c语言·算法
行思理2 小时前
Linux 下SVN新手操作手册
linux·运维·svn
hunandede2 小时前
Ubuntu网络配置(桥接模式, nat模式, host主机模式)
网络·ubuntu·桥接模式
初学者丶一起加油2 小时前
C语言基础:指针(数组指针与指针数组)
linux·c语言·开发语言·数据结构·c++·算法·visual studio
一只搬砖的猹3 小时前
cJson系列——常用cJson库函数
linux·前端·javascript·python·物联网·mysql·json
莫固执,朋友3 小时前
Linux下编译 libwebsockets简介和使用示例
linux·websocket·音视频
DCTANT4 小时前
【合作原创】使用Termux搭建可以使用的生产力环境(八)
linux·debian·idea·termux·vnc·xfce4·termux-x11