Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"command 'x86_64-linux-gnu-gcc' failed with exit status 1" error while installing MuJoCo on Google Colab #690

Closed
Saptam04 opened this issue Feb 20, 2022 · 4 comments

Comments

@Saptam04
Copy link

Describe the bug
I'm trying to install MuJoCo on Google Colab. I followed all the steps mentioned in mujoco-py's GitHub page (i.e. setting the environment variables and installing additional packages). When I import mujoco_py or use gym.make() I get the following GCC error:

LinkError: command 'x86_64-linux-gnu-gcc' failed with exit status 1

I see that the same issue has been raised many times in the past (e.g. this and this). Does anybody know how to get it to run on Colab?

To Reproduce
Download MuJoCo and install mujoco-py.

Expected behavior
A fresh MuJoCo installation.

Error Messages
Following is the full error message:

running build_ext
building 'mujoco_py.cymj' extension
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fdebug-prefix-map=/build/python3.7-pX47U3/python3.7-3.7.12=. -fstack-protector-strong -Wformat -Werror=format-security -g -fdebug-prefix-map=/build/python3.7-pX47U3/python3.7-3.7.12=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.7/dist-packages/mujoco_py -I/root/.mujoco/mujoco211/include -I/usr/local/lib/python3.7/dist-packages/numpy/core/include -I/usr/include/python3.7m -c /usr/local/lib/python3.7/dist-packages/mujoco_py/cymj.c -o /usr/local/lib/python3.7/dist-packages/mujoco_py/generated/_pyxbld_2.1.2.14_37_linuxcpuextensionbuilder/temp.linux-x86_64-3.7/usr/local/lib/python3.7/dist-packages/mujoco_py/cymj.o -fopenmp -w
x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fdebug-prefix-map=/build/python3.7-pX47U3/python3.7-3.7.12=. -fstack-protector-strong -Wformat -Werror=format-security -g -fdebug-prefix-map=/build/python3.7-pX47U3/python3.7-3.7.12=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.7/dist-packages/mujoco_py -I/root/.mujoco/mujoco211/include -I/usr/local/lib/python3.7/dist-packages/numpy/core/include -I/usr/include/python3.7m -c /usr/local/lib/python3.7/dist-packages/mujoco_py/gl/osmesashim.c -o /usr/local/lib/python3.7/dist-packages/mujoco_py/generated/_pyxbld_2.1.2.14_37_linuxcpuextensionbuilder/temp.linux-x86_64-3.7/usr/local/lib/python3.7/dist-packages/mujoco_py/gl/osmesashim.o -fopenmp -w
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fdebug-prefix-map=/build/python3.7-pX47U3/python3.7-3.7.12=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 /usr/local/lib/python3.7/dist-packages/mujoco_py/generated/_pyxbld_2.1.2.14_37_linuxcpuextensionbuilder/temp.linux-x86_64-3.7/usr/local/lib/python3.7/dist-packages/mujoco_py/cymj.o /usr/local/lib/python3.7/dist-packages/mujoco_py/generated/_pyxbld_2.1.2.14_37_linuxcpuextensionbuilder/temp.linux-x86_64-3.7/usr/local/lib/python3.7/dist-packages/mujoco_py/gl/osmesashim.o -L/root/.mujoco/mujoco211/bin -Wl,--enable-new-dtags,-R/root/.mujoco/mujoco211/bin -lmujoco210 -lglewosmesa -lOSMesa -lGL -o /usr/local/lib/python3.7/dist-packages/mujoco_py/generated/_pyxbld_2.1.2.14_37_linuxcpuextensionbuilder/lib.linux-x86_64-3.7/mujoco_py/cymj.cpython-37m-x86_64-linux-gnu.so -fopenmp
---------------------------------------------------------------------------
DistutilsExecError                        Traceback (most recent call last)
[/usr/lib/python3.7/distutils/unixccompiler.py](https://localhost:8080/#) 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)
    214 
--> 215                 self.spawn(linker + ld_args)
    216             except DistutilsExecError as msg:

33 frames
[/usr/lib/python3.7/distutils/ccompiler.py](https://localhost:8080/#) in spawn(self, cmd)
    909     def spawn(self, cmd):
--> 910         spawn(cmd, dry_run=self.dry_run)
    911 

[/usr/lib/python3.7/distutils/spawn.py](https://localhost:8080/#) 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':

[/usr/lib/python3.7/distutils/spawn.py](https://localhost:8080/#) in _spawn_posix(cmd, search_path, verbose, dry_run)
    158                           "command %r failed with exit status %d"
--> 159                           % (cmd, exit_status))
    160             elif os.WIFSTOPPED(status):

DistutilsExecError: command 'x86_64-linux-gnu-gcc' failed with exit status 1

During handling of the above exception, another exception occurred:

LinkError                                 Traceback (most recent call last)
[<ipython-input-7-53120878d6a5>](https://localhost:8080/#) in <module>()
      1 import gym
      2 
----> 3 env = gym.make("Ant-v2")
      4 # import mujoco_py

[/usr/local/lib/python3.7/dist-packages/gym/envs/registration.py](https://localhost:8080/#) in make(id, **kwargs)
    143 
    144 def make(id, **kwargs):
--> 145     return registry.make(id, **kwargs)
    146 
    147 def spec(id):

[/usr/local/lib/python3.7/dist-packages/gym/envs/registration.py](https://localhost:8080/#) in make(self, path, **kwargs)
     88             logger.info('Making new env: %s', path)
     89         spec = self.spec(path)
---> 90         env = spec.make(**kwargs)
     91         # We used to have people override _reset/_step rather than
     92         # reset/step. Set _gym_disable_underscore_compat = True on

[/usr/local/lib/python3.7/dist-packages/gym/envs/registration.py](https://localhost:8080/#) in make(self, **kwargs)
     57             env = self.entry_point(**_kwargs)
     58         else:
---> 59             cls = load(self.entry_point)
     60             env = cls(**_kwargs)
     61 

[/usr/local/lib/python3.7/dist-packages/gym/envs/registration.py](https://localhost:8080/#) in load(name)
     16 def load(name):
     17     mod_name, attr_name = name.split(":")
---> 18     mod = importlib.import_module(mod_name)
     19     fn = getattr(mod, attr_name)
     20     return fn

[/usr/lib/python3.7/importlib/__init__.py](https://localhost:8080/#) in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

/usr/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

/usr/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

/usr/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

/usr/lib/python3.7/importlib/_bootstrap.py in _load_unlocked(spec)

/usr/lib/python3.7/importlib/_bootstrap_external.py in exec_module(self, module)

/usr/lib/python3.7/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

[/usr/local/lib/python3.7/dist-packages/gym/envs/mujoco/__init__.py](https://localhost:8080/#) in <module>()
----> 1 from gym.envs.mujoco.mujoco_env import MujocoEnv
      2 # ^^^^^ so that user gets the correct error
      3 # message if mujoco is not installed correctly
      4 from gym.envs.mujoco.ant import AntEnv
      5 from gym.envs.mujoco.half_cheetah import HalfCheetahEnv

[/usr/local/lib/python3.7/dist-packages/gym/envs/mujoco/mujoco_env.py](https://localhost:8080/#) in <module>()
     10 
     11 try:
---> 12     import mujoco_py
     13 except ImportError as e:
     14     raise error.DependencyNotInstalled("{}. (HINT: you need to install mujoco_py, and also perform the setup instructions here: https://github.com/openai/mujoco-py/.)".format(e))

[/usr/local/lib/python3.7/dist-packages/mujoco_py/__init__.py](https://localhost:8080/#) 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

[/usr/local/lib/python3.7/dist-packages/mujoco_py/builder.py](https://localhost:8080/#) in <module>()
    502 
    503 mujoco_path = discover_mujoco()
--> 504 cymj = load_cython_ext(mujoco_path)
    505 
    506 

[/usr/local/lib/python3.7/dist-packages/mujoco_py/builder.py](https://localhost:8080/#) 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 

[/usr/local/lib/python3.7/dist-packages/mujoco_py/builder.py](https://localhost:8080/#) 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)

[/usr/local/lib/python3.7/dist-packages/mujoco_py/builder.py](https://localhost:8080/#) in _build_impl(self)
    276 
    277     def _build_impl(self):
--> 278         so_file_path = super()._build_impl()
    279         # Removes absolute paths to libraries. Allows for dynamic loading.
    280         fix_shared_library(so_file_path, 'libmujoco210.so', 'libmujoco210.so')

[/usr/local/lib/python3.7/dist-packages/mujoco_py/builder.py](https://localhost:8080/#) 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

[/usr/lib/python3.7/distutils/dist.py](https://localhost:8080/#) in run_commands(self)
    964         """
    965         for cmd in self.commands:
--> 966             self.run_command(cmd)
    967 
    968     # -- Methods that operate on its Commands --------------------------

[/usr/lib/python3.7/distutils/dist.py](https://localhost:8080/#) 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 

[/usr/local/lib/python3.7/dist-packages/Cython/Distutils/old_build_ext.py](https://localhost:8080/#) in run(self)
    184             optimization.disable_optimization()
    185 
--> 186         _build_ext.build_ext.run(self)
    187 
    188     def build_extensions(self):

[/usr/lib/python3.7/distutils/command/build_ext.py](https://localhost:8080/#) in run(self)
    338 
    339         # Now actually compile and link everything.
--> 340         self.build_extensions()
    341 
    342     def check_extensions_list(self, extensions):

[/usr/local/lib/python3.7/dist-packages/mujoco_py/builder.py](https://localhost:8080/#) in build_extensions(self)
    147         except (AttributeError, ValueError):
    148             pass
--> 149         build_ext.build_extensions(self)
    150 
    151 

[/usr/local/lib/python3.7/dist-packages/Cython/Distutils/old_build_ext.py](https://localhost:8080/#) 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):

[/usr/lib/python3.7/distutils/command/build_ext.py](https://localhost:8080/#) in build_extensions(self)
    447             self._build_extensions_parallel()
    448         else:
--> 449             self._build_extensions_serial()
    450 
    451     def _build_extensions_parallel(self):

[/usr/lib/python3.7/distutils/command/build_ext.py](https://localhost:8080/#) 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

[/usr/lib/python3.7/distutils/command/build_ext.py](https://localhost:8080/#) in build_extension(self, ext)
    557             debug=self.debug,
    558             build_temp=self.build_temp,
--> 559             target_lang=language)
    560 
    561     def swig_sources(self, sources, extension):

[/usr/lib/python3.7/distutils/ccompiler.py](https://localhost:8080/#) 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)
    715                   libraries, library_dirs, runtime_library_dirs,
    716                   export_symbols, debug,
--> 717                   extra_preargs, extra_postargs, build_temp, target_lang)
    718 
    719 

[/usr/lib/python3.7/distutils/unixccompiler.py](https://localhost:8080/#) 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)
    215                 self.spawn(linker + ld_args)
    216             except DistutilsExecError as msg:
--> 217                 raise LinkError(msg)
    218         else:
    219             log.debug("skipping %s (up-to-date)", output_filename)

LinkError: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Desktop

  • OS: Ubuntu 18.04.5 LTS (Bionic Beaver)
  • Python Version: 3.7.12
  • Mujoco Version: 2.1.1 Linux (x86_64)
  • mujoco-py version: 2.1.2.14

Environment

  • output of: echo $LD_LIBRARY_PATH
    /usr/local/nvidia/lib:/usr/local/nvidia/lib64:/root/.mujoco/mujoco211/bin
  • output of: echo $HOME
    /root
  • output of: echo $USER
    No output.

Additional context
I installed the following additional packages as suggested in the Docker file:

!sudo apt-get install \
   patchelf \
   curl \
   git \
   libgl1-mesa-dev \
   libgl1-mesa-glx \
   libglew-dev \
   libglfw3 \
   libosmesa6-dev \
   python3-pip \
   python3-numpy \
   python3-scipy \
   net-tools \
   unzip \
   vim \
   wget \
   xpra \
   xserver-xorg-dev

PS: I tried to downgrade mujoco-py. All of the versions from 2.0.2.13 to 2.0.2.9 even fails to install using pip. Version 2.0.2.8 installs, but produces the same error mentioned above.

@Saptam04 Saptam04 changed the title "command 'x86_64-linux-gnu-gcc' failed with exit status 1" error while trying to install MuJoCo on Google Colab "command 'x86_64-linux-gnu-gcc' failed with exit status 1" error while installing MuJoCo on Google Colab Feb 20, 2022
@atonkamanda
Copy link

I've gone to the same error as you and finally found a fix, first the fix for a local setup won't work here for colab.

The real fix is to not do the old way of installing mujoco with the key and the binaries, causing dependencies and path issues.

Now that it is free, you can just do

!pip install free-mujoco-py

Without having to care about mjkey/environments variables.

You can check this example to make sure you are not missing any libraries or adding some useless one.
https://colab.research.google.com/drive/1KGMZdRq6AemfcNscKjgpRzXqfhUtCf-V?usp=sharing#scrollTo=3qeAEFtTG8dV

Should be fixed after that, tag me if it's not.

@atonkamanda
Copy link

I should add that installing free-mujoco isn't something you add on the top of the other installation, otherwise it won't work, just get rid of the old files and do like in the notebook.

Hope it helps.

@Saptam04
Copy link
Author

@atonkamanda Thanks for the fix. In fact shortly after posting it, I found out this Reddit post and this pull request where they point to this exact notebook.

A bit of a rant: now that MuJoCo is freely available (kudos Deepmind), I think the authors and the maintainers REALLY should try to put in some effort to make it a little bit more user-friendly. As it stands, it is undoubtedly a hassle to install it even on the most popular platforms like Ubuntu and Debian. I recently had the opportunity of installing it on a Manjaro-based system, and I can confirm that it was truly a nightmare!

@Nov05
Copy link

Nov05 commented Mar 2, 2024

I've gone to the same error as you and finally found a fix, first the fix for a local setup won't work here for colab.
The real fix is to not do the old way of installing mujoco with the key and the binaries, causing dependencies and path issues.
Now that it is free, you can just do

!pip install free-mujoco-py

Without having to care about mjkey/environments variables.
You can check this example to make sure you are not missing any libraries or adding some useless one. https://colab.research.google.com/drive/1KGMZdRq6AemfcNscKjgpRzXqfhUtCf-V?usp=sharing#scrollTo=3qeAEFtTG8dV
Should be fixed after that, tag me if it's not.

yep, this works for me. thank you very much!

!apt-get install -y \
    libgl1-mesa-dev \
    libgl1-mesa-glx \
    libglew-dev \
    libosmesa6-dev \
    software-properties-common
!apt-get install -y patchelf
!pip install free-mujoco-py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants