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

相关推荐
饮浊酒32 分钟前
Linux操作系统 ------(3.文本编译器Vim)
linux·vim
lihuhelihu40 分钟前
第3章 CentOS系统管理
linux·运维·服务器·计算机网络·ubuntu·centos·云计算
矛取矛求1 小时前
Linux系统性能调优技巧
linux
One_Blanks1 小时前
渗透测试-Linux基础(1)
linux·运维·安全
Perishell1 小时前
无人机避障——大疆与Airsim中的角速度信息订阅获取
linux·动态规划·无人机
爱吃喵的鲤鱼1 小时前
linux进程的状态之环境变量
linux·运维·服务器·开发语言·c++
dessler1 小时前
Linux系统-ubuntu系统安装
linux·运维·云计算
荒Huang2 小时前
Linux挖矿病毒(kswapd0进程使cpu爆满)
linux·运维·服务器
零意@2 小时前
ubuntu切换不同版本的python
windows·python·ubuntu
hjjdebug4 小时前
linux 下 signal() 函数的用法,信号类型在哪里定义的?
linux·signal