openai / mujoco-py

MuJoCo is a physics engine for detailed, efficient rigid body simulations with contacts. mujoco-py allows using MuJoCo from Python 3.
Other
2.89k stars 813 forks source link

ld: library not found for -lSystem (OSX Monterey) #655

Open StijnTassenoy opened 3 years ago

StijnTassenoy commented 3 years ago

I tried to fresh install mujoco-py on my Mac, but everytime I would like to import mujoco_py, I get following error. (I followed all steps for the installation process...)

running build_ext
building 'mujoco_py.cymj' extension
/usr/local/opt/llvm/bin/clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -I/usr/local/opt/llvm/include -DONMAC -I/Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py -I/Users/stasseno/.mujoco/mujoco210/include -I/Users/stasseno/Library/Python/3.8/lib/python/site-packages/numpy/core/include -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -c /Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py/cymj.c -o /Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14-x86_64-3.8/Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py/cymj.o -fopenmp -w
/usr/local/opt/llvm/bin/clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -I/usr/local/opt/llvm/include -DONMAC -I/Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py -I/Users/stasseno/.mujoco/mujoco210/include -I/Users/stasseno/Library/Python/3.8/lib/python/site-packages/numpy/core/include -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8 -c /Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py/gl/dummyshim.c -o /Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14-x86_64-3.8/Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py/gl/dummyshim.o -fopenmp -w
/usr/local/opt/llvm/bin/clang -bundle -undefined dynamic_lookup -arch arm64 -arch x86_64 -Wl,-headerpad,0x1000 -L/usr/local/opt/llvm/lib -I/usr/local/opt/llvm/include /Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14-x86_64-3.8/Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py/cymj.o /Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/temp.macosx-10.14-x86_64-3.8/Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py/gl/dummyshim.o -L/Users/stasseno/.mujoco/mujoco210/bin -L/Users/stasseno/.mujoco/mujoco210/bin -lmujoco210 -lglfw.3 -o /Users/stasseno/Library/Python/3.8/lib/python/site-packages/mujoco_py/generated/_pyxbld_2.1.2.14_38_macextensionbuilder/lib.macosx-10.14-x86_64-3.8/mujoco_py/cymj.cpython-38-darwin.so -fopenmp

ld: library not found for -lSystem
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
DistutilsExecError                        Traceback (most recent call last)
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/unixccompiler.py in link(self, target_desc, objects, output_filename, output_dir, libraries, library_dirs, runtime_library_dirs, export_symbols, debug, extra_preargs, extra_postargs, build_temp, target_lang)
    204 
--> 205                 self.spawn(linker + ld_args)
    206             except DistutilsExecError as msg:

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/ccompiler.py in spawn(self, cmd)
    909     def spawn(self, cmd):
--> 910         spawn(cmd, dry_run=self.dry_run)
    911 

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/spawn.py in spawn(cmd, search_path, verbose, dry_run)
     35     if os.name == 'posix':
---> 36         _spawn_posix(cmd, search_path, dry_run=dry_run)
     37     elif os.name == 'nt':

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/spawn.py in _spawn_posix(cmd, search_path, verbose, dry_run)
    156                         cmd = executable
--> 157                     raise DistutilsExecError(
    158                           "command %r failed with exit status %d"

DistutilsExecError: command '/usr/local/opt/llvm/bin/clang' failed with exit status 1

During handling of the above exception, another exception occurred:

LinkError                                 Traceback (most recent call last)
LinkError                                 Traceback (most recent call last)
/var/folders/yt/g53rz97524s21wt607xnx0fr0000gn/T/ipykernel_625/2179802279.py in <module>
----> 1 import mujoco_py

~/Library/Python/3.8/lib/python/site-packages/mujoco_py/__init__.py in <module>
      1 #!/usr/bin/env python
----> 2 from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
      3 from mujoco_py.generated import const
      4 from mujoco_py.mjrenderpool import MjRenderPool
      5 from mujoco_py.mjviewer import MjViewer, MjViewerBasic

~/Library/Python/3.8/lib/python/site-packages/mujoco_py/builder.py in <module>
    502 
    503 mujoco_path = discover_mujoco()
--> 504 cymj = load_cython_ext(mujoco_path)
    505 
    506 

~/Library/Python/3.8/lib/python/site-packages/mujoco_py/builder.py in load_cython_ext(mujoco_path)
    108                 print("Import error. Trying to rebuild mujoco_py.")
    109         if mod is None:
--> 110             cext_so_path = builder.build()
    111             mod = load_dynamic_ext('cymj', cext_so_path)
    112 

~/Library/Python/3.8/lib/python/site-packages/mujoco_py/builder.py in build(self)
    224 
    225     def build(self):
--> 226         built_so_file_path = self._build_impl()
    227         new_so_file_path = self.get_so_file_path()
    228         move(built_so_file_path, new_so_file_path)

~/Library/Python/3.8/lib/python/site-packages/mujoco_py/builder.py in _build_impl(self)
    341             del os.environ['CC']
    342         else:  # User-directed c compiler
--> 343             so_file_path = super()._build_impl()
    344         return manually_link_libraries(self.mujoco_path, so_file_path)
    345 
~/Library/Python/3.8/lib/python/site-packages/mujoco_py/builder.py in _build_impl(self)
    247         dist.parse_command_line()
    248         obj_build_ext = dist.get_command_obj("build_ext")
--> 249         dist.run_commands()
    250         built_so_file_path, = obj_build_ext.get_outputs()
    251         return built_so_file_path

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/dist.py in run_commands(self)
    964         """
    965         for cmd in self.commands:
--> 966             self.run_command(cmd)
    967 
    968     # -- Methods that operate on its Commands --------------------------

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/dist.py in run_command(self, command)
    983         cmd_obj = self.get_command_obj(command)
    984         cmd_obj.ensure_finalized()
--> 985         cmd_obj.run()
    986         self.have_run[command] = 1
    987 

~/Library/Python/3.8/lib/python/site-packages/Cython/Distutils/old_build_ext.py in run(self)
    184             optimization.disable_optimization()
    185 
--> 186         _build_ext.build_ext.run(self)
    187 
    188     def build_extensions(self):

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/command/build_ext.py in run(self)
    338 
    339         # Now actually compile and link everything.
--> 340         self.build_extensions()
    341 
    342     def check_extensions_list(self, extensions):
~/Library/Python/3.8/lib/python/site-packages/mujoco_py/builder.py in build_extensions(self)
    147         except (AttributeError, ValueError):
    148             pass
--> 149         build_ext.build_extensions(self)
    150 
    151 

~/Library/Python/3.8/lib/python/site-packages/Cython/Distutils/old_build_ext.py in build_extensions(self)
    193             ext.sources = self.cython_sources(ext.sources, ext)
    194         # Call original build_extensions
--> 195         _build_ext.build_ext.build_extensions(self)
    196 
    197     def cython_sources(self, sources, extension):

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/command/build_ext.py in build_extensions(self)
    447             self._build_extensions_parallel()
    448         else:
--> 449             self._build_extensions_serial()
    450 
    451     def _build_extensions_parallel(self):
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/command/build_ext.py in _build_extensions_serial(self)
    472         for ext in self.extensions:
    473             with self._filter_build_errors(ext):
--> 474                 self.build_extension(ext)
    475 
    476     @contextlib.contextmanager

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/command/build_ext.py in build_extension(self, ext)
    548         language = ext.language or self.compiler.detect_language(sources)
    549 
--> 550         self.compiler.link_shared_object(
    551             objects, ext_path,
    552             libraries=self.get_libraries(ext),

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/ccompiler.py in link_shared_object(self, objects, output_filename, output_dir, libraries, library_dirs, runtime_library_dirs, export_symbols, debug, extra_preargs, extra_postargs, build_temp, target_lang)
    711                            build_temp=None,
    712                            target_lang=None):
--> 713         self.link(CCompiler.SHARED_OBJECT, objects,
    714                   output_filename, output_dir,
    715                   libraries, library_dirs, runtime_library_dirs,

/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/distutils/unixccompiler.py in link(self, target_desc, objects, output_filename, output_dir, libraries, library_dirs, runtime_library_dirs, export_symbols, debug, extra_preargs, extra_postargs, build_temp, target_lang)
    205                 self.spawn(linker + ld_args)
    206             except DistutilsExecError as msg:
--> 207                 raise LinkError(msg)
    208         else:
    209             log.debug("skipping %s (up-to-date)", output_filename)

LinkError: command '/usr/local/opt/llvm/bin/clang' failed with exit status 1
djumpstre commented 2 years ago

Hallo,

I have the same problem on Monterey with intel CPU. To solve this

Firstly, add usr/lib* to $LIBRARY_PAT in .bash_profile

export LIBRARY_PATH="$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib" Then source the .bash_profile again.

Secondly, the last clang command to bundle the library has the -arch arm64 and -arch x86_64 repeatedly. See: /usr/local/opt/llvm/bin/clang -bundle -undefined dynamic_lookup -arch arm64 -arch x86_64 -Wl,-headerpad,0x1000

I haven't figure out why it was given twice. In my case, I remove the -arch arm64 and execute this line manually after the compiler error comes out. Then it works well with OpenMP and OpenGL.