根据本文档导入 mujoco_py 时,cymj 扩展构建失败并出现 clang-10 错误(见下文)。当我这样做时也会发生此错误
brew uninstall gcc && brew install gcc@x
(x 为 6、8、9)。执行此命令也无济于事:conda install -c conda-forge openmp
. 在运行这些命令之前,Pip 和 brew 已更新/升级到最新版本。mujoco builder.py 中的 gcc-9 编译器行(以及版本 7 和 8 的编译器行)处于活动状态。从这个问题应用 sdk 文件夹复制和重命名技巧也没有帮助。
这是完整的标准输出/标准错误:
$ python3
Python 3.7.7 (default, May 6 2020, 04:59:01)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mujoco_py
Import error. Trying to rebuild mujoco_py.
running build_ext
building 'mujoco_py.cymj' extension
/usr/local/opt/llvm/bin/clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Users/fabioferreira/miniconda3/envs/gtn/include -arch x86_64 -I/Users/fabioferreira/miniconda3/envs/gtn/include -arch x86_64 -I/usr/local/opt/llvm/include -DONMAC -I/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py -I/Users/fabioferreira/.mujoco/mujoco200/include -I/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/numpy/core/include -I/Users/fabioferreira/miniconda3/envs/gtn/include/python3.7m -c /Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/cymj.c -o /Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/generated/_pyxbld_2.0.2.10_37_macextensionbuilder/temp.macosx-10.9-x86_64-3.7/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/cymj.o -fopenmp -w
/usr/local/opt/llvm/bin/clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Users/fabioferreira/miniconda3/envs/gtn/include -arch x86_64 -I/Users/fabioferreira/miniconda3/envs/gtn/include -arch x86_64 -I/usr/local/opt/llvm/include -DONMAC -I/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py -I/Users/fabioferreira/.mujoco/mujoco200/include -I/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/numpy/core/include -I/Users/fabioferreira/miniconda3/envs/gtn/include/python3.7m -c /Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/gl/dummyshim.c -o /Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/generated/_pyxbld_2.0.2.10_37_macextensionbuilder/temp.macosx-10.9-x86_64-3.7/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/gl/dummyshim.o -fopenmp -w
/usr/local/opt/llvm/bin/clang -bundle -undefined dynamic_lookup -L/Users/fabioferreira/miniconda3/envs/gtn/lib -arch x86_64 -L/Users/fabioferreira/miniconda3/envs/gtn/lib -arch x86_64 -L/usr/local/opt/llvm/lib -I/usr/local/opt/llvm/include -arch x86_64 /Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/generated/_pyxbld_2.0.2.10_37_macextensionbuilder/temp.macosx-10.9-x86_64-3.7/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/cymj.o /Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/generated/_pyxbld_2.0.2.10_37_macextensionbuilder/temp.macosx-10.9-x86_64-3.7/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/gl/dummyshim.o -L/Users/fabioferreira/.mujoco/mujoco200/bin -L/Users/fabioferreira/.mujoco/mujoco200/bin -lmujoco200 -lglfw.3 -o /Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/generated/_pyxbld_2.0.2.10_37_macextensionbuilder/lib.macosx-10.9-x86_64-3.7/mujoco_py/cymj.cpython-37m-darwin.so -fopenmp
ld: unknown option: -platform_version <------------------------------ error
clang-10: error: linker command failed with exit code 1 (use -v to see invocation) <-------------- error
Traceback (most recent call last):
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/distutils/unixccompiler.py", line 205, in link
self.spawn(linker + ld_args)
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/distutils/ccompiler.py", line 910, in spawn
spawn(cmd, dry_run=self.dry_run)
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/distutils/spawn.py", line 36, in spawn
_spawn_posix(cmd, search_path, dry_run=dry_run)
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/distutils/spawn.py", line 159, in _spawn_posix
% (cmd, exit_status))
distutils.errors.DistutilsExecError: command '/usr/local/opt/llvm/bin/clang' 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 "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/__init__.py", line 3, in <module>
from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/builder.py", line 510, in <module>
cymj = load_cython_ext(mujoco_path)
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/builder.py", line 105, in load_cython_ext
cext_so_path = builder.build()
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/builder.py", line 221, in build
built_so_file_path = self._build_impl()
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/builder.py", line 338, in _build_impl
so_file_path = super()._build_impl()
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/builder.py", line 244, in _build_impl
dist.run_commands()
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/Cython/Distutils/old_build_ext.py", line 186, in run
_build_ext.build_ext.run(self)
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/distutils/command/build_ext.py", line 340, in run
self.build_extensions()
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/mujoco_py/builder.py", line 144, in build_extensions
build_ext.build_extensions(self)
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/site-packages/Cython/Distutils/old_build_ext.py", line 195, in build_extensions
_build_ext.build_ext.build_extensions(self)
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/distutils/command/build_ext.py", line 449, in build_extensions
self._build_extensions_serial()
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/distutils/command/build_ext.py", line 474, in _build_extensions_serial
self.build_extension(ext)
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/distutils/command/build_ext.py", line 559, in build_extension
target_lang=language)
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/distutils/ccompiler.py", line 717, in link_shared_object
extra_preargs, extra_postargs, build_temp, target_lang)
File "/Users/fabioferreira/miniconda3/envs/gtn/lib/python3.7/distutils/unixccompiler.py", line 207, in link
raise LinkError(msg)
distutils.errors.LinkError: command '/usr/local/opt/llvm/bin/clang' failed with exit status 1
版本:
- 操作系统:[例如 macOS 10.13.6] macOS 10.15.5
- Python 版本 [例如 3.6.6] Python 3.7.7
- Mujoco 版本 [例如 1.50] 2.0.0
- mujoco-py 版本 [例如 1.50.1.59] 2.0.2.10
附加上下文
$ brew info llvm
llvm: stable 10.0.0 (bottled), HEAD [keg-only]
Next-gen compiler infrastructure
https://llvm.org/
/usr/local/Cellar/llvm/10.0.0_3 (7,055 files, 1GB)
Poured from bottle on 2020-07-03 at 19:38:12
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/llvm.rb
==> Dependencies
Build: cmake ✔, python@3.8 ✔
Required: libffi ✔
==> Requirements
Build: xcode ✔
==> Options
--HEAD
$ brew info gcc
gcc: stable 10.1.0 (bottled), HEAD
GNU compiler collection
https://gcc.gnu.org/
/usr/local/Cellar/gcc/10.1.0 (1,463 files, 338.5MB) *
Poured from bottle on 2020-07-03 at 19:31:35
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/gcc.rb
==> Dependencies
Required: gmp ✔, isl ✔, libmpc ✔, mpfr ✔
==> Options
--HEAD
$ brew info boost
boost: stable 1.72.0 (bottled), HEAD
Collection of portable C++ source libraries
https://www.boost.org/
/usr/local/Cellar/boost/1.72.0_3 (14,466 files, 563.8MB) *
Poured from bottle on 2020-07-03 at 19:31:23
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/boost.rb
==> Dependencies
Required: icu4c ✔
==> Options
--HEAD
$ brew info hdf5
hdf5: stable 1.12.0 (bottled)
File format designed to store large amounts of data
https://www.hdfgroup.org/HDF5
/usr/local/Cellar/hdf5/1.12.0_1 (268 files, 16.3MB) *
Poured from bottle on 2020-07-03 at 19:31:39
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/hdf5.rb
==> Dependencies
Build: autoconf ✔, automake ✔, libtool ✔
Required: gcc ✔, szip ✔
$ /usr/bin/xcodebuild -version
Xcode 11.5
Build version 11E608c
$ ld -v
@(#)PROGRAM:ld PROJECT:ld64-274.2
configured to support archs: i386 x86_64 x86_64h armv6 armv7 armv7s armv7m armv7k arm64 (tvOS)
LTO support using: LLVM version 5.0.0
我的 ~/.zshrc 中有以下几行:
15 # mujoco
16 export PATH="/usr/local/opt/llvm/bin:$PATH"
17
18 export CC="/usr/local/opt/llvm/bin/clang"
19 export CXX="/usr/local/opt/llvm/bin/clang++"
20 export CXX11="/usr/local/opt/llvm/bin/clang++"
21 export CXX14="/usr/local/opt/llvm/bin/clang++"
22 export CXX17="/usr/local/opt/llvm/bin/clang++"
23 export CXX1X="/usr/local/opt/llvm/bin/clang++"
24 export LDFLAGS="-L/usr/local/opt/llvm/lib"
25 export CPPFLAGS="-I/usr/local/opt/llvm/include"