前言
在Linux下安装软件,还是容易出现各种问题,而且是用命令行操作的,往往会出现长长的报错。这时候就需要非常强大的阅读报错的能力。
总而言之,就是缺啥装啥。
open OL库
出现报错如下:
$ python
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
Python 3.8.13 (default, Mar 28 2022, 11:38:47)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mujoco_py
running build_ext
building 'mujoco_py.cymj' extension
gcc -pthread -B /home/user/miniconda3/envs/py38/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py -I/home/user/.mujoco/mujoco200/include -I/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/numpy/core/include -I/home/user/miniconda3/envs/py38/include/python3.8 -c /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/cymj.c -o /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.0.2.8_38_linuxcpuextensionbuilder/temp.linux-x86_64-3.8/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/cymj.o -fopenmp -w
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
gcc -pthread -B /home/user/miniconda3/envs/py38/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py -I/home/user/.mujoco/mujoco200/include -I/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/numpy/core/include -I/home/user/miniconda3/envs/py38/include/python3.8 -c /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/gl/osmesashim.c -o /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.0.2.8_38_linuxcpuextensionbuilder/temp.linux-x86_64-3.8/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/gl/osmesashim.o -fopenmp -w
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/gl/osmesashim.c:1:10: fatal error: GL/osmesa.h: No such file or directory
1 | #include <GL/osmesa.h>
| ^~~~~~~~~~~~~
compilation terminated.
Traceback (most recent call last):
File "/home/user/miniconda3/envs/py38/lib/python3.8/distutils/unixccompiler.py", line 117, in _compile
self.spawn(compiler_so + cc_args + [src, '-o', obj] +
File "/home/user/miniconda3/envs/py38/lib/python3.8/distutils/ccompiler.py", line 910, in spawn
spawn(cmd, dry_run=self.dry_run)
File "/home/user/miniconda3/envs/py38/lib/python3.8/distutils/spawn.py", line 36, in spawn
_spawn_posix(cmd, search_path, dry_run=dry_run)
File "/home/user/miniconda3/envs/py38/lib/python3.8/distutils/spawn.py", line 157, in _spawn_posix
raise DistutilsExecError(
distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/__init__.py", line 3, in <module>
from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/builder.py", line 506, in <module>
cymj = load_cython_ext(mujoco_path)
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/builder.py", line 105, in load_cython_ext
cext_so_path = builder.build()
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/builder.py", line 221, in build
built_so_file_path = self._build_impl()
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/builder.py", line 273, in _build_impl
so_file_path = super()._build_impl()
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/builder.py", line 244, in _build_impl
dist.run_commands()
File "/home/user/miniconda3/envs/py38/lib/python3.8/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/home/user/miniconda3/envs/py38/lib/python3.8/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
_build_ext.build_ext.run(self)
File "/home/user/miniconda3/envs/py38/lib/python3.8/distutils/command/build_ext.py", line 340, in run
self.build_extensions()
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/builder.py", line 144, in build_extensions
build_ext.build_extensions(self)
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions
_build_ext.build_ext.build_extensions(self)
File "/home/user/miniconda3/envs/py38/lib/python3.8/distutils/command/build_ext.py", line 449, in build_extensions
self._build_extensions_serial()
File "/home/user/miniconda3/envs/py38/lib/python3.8/distutils/command/build_ext.py", line 474, in _build_extensions_serial
self.build_extension(ext)
File "/home/user/miniconda3/envs/py38/lib/python3.8/distutils/command/build_ext.py", line 528, in build_extension
objects = self.compiler.compile(sources,
File "/home/user/miniconda3/envs/py38/lib/python3.8/distutils/ccompiler.py", line 574, in compile
self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
File "/home/user/miniconda3/envs/py38/lib/python3.8/distutils/unixccompiler.py", line 120, in _compile
raise CompileError(msg)
distutils.errors.CompileError: command 'gcc' failed with exit status 1
在这里,最重要的一句就是
fatal error: GL/osmesa.h: No such file or directory
1 | #include <GL/osmesa.h>
| ^~~~~~~~~~~~~
大概意思就是:出现了致命的错误:没有GL/osmesa.h这个文件。
说明此时缺了OpenGL,这是一个c语言中图形化的一个库,因此我们需要安装这个库。
执行如下命令即可安装:
$ sudo apt install libosmesa6-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libllvm9
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
libosmesa6
The following NEW packages will be installed:
libosmesa6 libosmesa6-dev
0 upgraded, 2 newly installed, 0 to remove and 37 not upgraded.
Need to get 3,063 kB of archives.
After this operation, 13.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://cn.archive.ubuntu.com/ubuntu focal-updates/main amd64 libosmesa6 amd64 21.2.6-0ubuntu0.1~20.04.2 [3,054 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu focal-updates/main amd64 libosmesa6-dev amd64 21.2.6-0ubuntu0.1~20.04.2 [8,844 B]
Fetched 3,063 kB in 5s (615 kB/s)
Selecting previously unselected package libosmesa6:amd64.
(Reading database ... 128268 files and directories currently installed.)
Preparing to unpack .../libosmesa6_21.2.6-0ubuntu0.1~20.04.2_amd64.deb ...
Unpacking libosmesa6:amd64 (21.2.6-0ubuntu0.1~20.04.2) ...
Selecting previously unselected package libosmesa6-dev:amd64.
Preparing to unpack .../libosmesa6-dev_21.2.6-0ubuntu0.1~20.04.2_amd64.deb ...
Unpacking libosmesa6-dev:amd64 (21.2.6-0ubuntu0.1~20.04.2) ...
Setting up libosmesa6:amd64 (21.2.6-0ubuntu0.1~20.04.2) ...
Setting up libosmesa6-dev:amd64 (21.2.6-0ubuntu0.1~20.04.2) ...
Processing triggers for libc-bin (2.31-0ubuntu9.7) ...
patchelf
出现报错如下:
$ python
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
Python 3.8.13 (default, Mar 28 2022, 11:38:47)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mujoco_py
running build_ext
building 'mujoco_py.cymj' extension
gcc -pthread -B /home/user/miniconda3/envs/py38/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py -I/home/user/.mujoco/mujoco200/include -I/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/numpy/core/include -I/home/user/miniconda3/envs/py38/include/python3.8 -c /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/cymj.c -o /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.0.2.8_38_linuxcpuextensionbuilder/temp.linux-x86_64-3.8/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/cymj.o -fopenmp -w
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
gcc -pthread -B /home/user/miniconda3/envs/py38/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py -I/home/user/.mujoco/mujoco200/include -I/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/numpy/core/include -I/home/user/miniconda3/envs/py38/include/python3.8 -c /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/gl/osmesashim.c -o /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.0.2.8_38_linuxcpuextensionbuilder/temp.linux-x86_64-3.8/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/gl/osmesashim.o -fopenmp -w
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
creating /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.0.2.8_38_linuxcpuextensionbuilder/lib.linux-x86_64-3.8
creating /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.0.2.8_38_linuxcpuextensionbuilder/lib.linux-x86_64-3.8/mujoco_py
gcc -pthread -shared -B /home/user/miniconda3/envs/py38/compiler_compat -L/home/user/miniconda3/envs/py38/lib -Wl,-rpath=/home/user/miniconda3/envs/py38/lib -Wl,--no-as-needed -Wl,--sysroot=/ /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.0.2.8_38_linuxcpuextensionbuilder/temp.linux-x86_64-3.8/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/cymj.o /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.0.2.8_38_linuxcpuextensionbuilder/temp.linux-x86_64-3.8/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/gl/osmesashim.o -L/home/user/.mujoco/mujoco200/bin -Wl,-R/home/user/.mujoco/mujoco200/bin -lmujoco200 -lglewosmesa -lOSMesa -lGL -o /home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/generated/_pyxbld_2.0.2.8_38_linuxcpuextensionbuilder/lib.linux-x86_64-3.8/mujoco_py/cymj.cpython-38-x86_64-linux-gnu.so -fopenmp
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/__init__.py", line 3, in <module>
from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/builder.py", line 506, in <module>
cymj = load_cython_ext(mujoco_path)
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/builder.py", line 105, in load_cython_ext
cext_so_path = builder.build()
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/builder.py", line 221, in build
built_so_file_path = self._build_impl()
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/builder.py", line 275, in _build_impl
fix_shared_library(so_file_path, 'libmujoco200.so', 'libmujoco200.so')
File "/home/user/miniconda3/envs/py38/lib/python3.8/site-packages/mujoco_py/builder.py", line 149, in fix_shared_library
subprocess.check_call(['patchelf', '--remove-rpath', so_file])
File "/home/user/miniconda3/envs/py38/lib/python3.8/subprocess.py", line 359, in check_call
retcode = call(*popenargs, **kwargs)
File "/home/user/miniconda3/envs/py38/lib/python3.8/subprocess.py", line 340, in call
with Popen(*popenargs, **kwargs) as p:
File "/home/user/miniconda3/envs/py38/lib/python3.8/subprocess.py", line 858, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/home/user/miniconda3/envs/py38/lib/python3.8/subprocess.py", line 1704, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'patchelf'
这里面最重要的一句话就是
FileNotFoundError: [Errno 2] No such file or directory: 'patchelf'
它的意思就是:文件错误:找不到patchelf
同样,缺啥装啥,执行如下命令:
$ sudo apt-get install patchelf
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libllvm9
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
patchelf
0 upgraded, 1 newly installed, 0 to remove and 37 not upgraded.
Need to get 53.4 kB of archives.
After this operation, 153 kB of additional disk space will be used.
Get:1 http://cn.archive.ubuntu.com/ubuntu focal/universe amd64 patchelf amd64 0.10-2build1 [53.4 kB]
Fetched 53.4 kB in 2s (31.0 kB/s)
Selecting previously unselected package patchelf.
(Reading database ... 128287 files and directories currently installed.)
Preparing to unpack .../patchelf_0.10-2build1_amd64.deb ...
Unpacking patchelf (0.10-2build1) ...
Setting up patchelf (0.10-2build1) ...
Processing triggers for man-db (2.9.1-1) ...
LD_PRELOAD
这是一个动态数据库加载的路径,出现报错如下:
python
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
Python 3.8.13 (default, Mar 28 2022, 11:38:47)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mujoco_py
running build_ext
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
ERROR: ld.so: object '/usr/lib/x86_64-linux-gnu/libGLEW.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
这个并不要紧,只需要执行:unset LD_PRELOAD
即可