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

mujoco_py issue when creating a conda environment. Same code runs fine in a Python venv environment. #102

Closed
ChristosPeridis opened this issue Jul 6, 2023 · 3 comments
Labels
good first issue Good for newcomers

Comments

@ChristosPeridis
Copy link

Hello dear Dr. Vikash,

How are you doing? I hope you are doing well. I had to conduct some research during the past week so I postponed working on the RoboHive API. I am starting again from today. Before I had successfully made a Python3 venv virtual environment, where I installed RoboHive.

In my system I had downloaded and extracted under the ".mujoco" folder mujoco200 simulator, along with its key and license. In order to make visible to the virtual environment the mujoco200 simulator I appended the following to the activate file of the bin folder of my venv virtual environment:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/.mujoco/mujoco200/bin
export MUJOCO_PY_MJKEY_PATH=
/.mujoco/mjkey.txt
export MUJOCO_PY_MUJOCO_PATH=~/.mujoco/mujoco200

After appending the above in the activate file of my venv environment I activated it and install RoboHive API from the cloned GitHub repository with the following command:

pip install -e ".[mujoco]"

Then I ran the example command : python robohive/utils/examine_env.py -e FrankaReachRandom-v0

And everything ran fine, I was able to see the simulation .

However, when I attempted to follow the same steps to install RoboHive API in a conda environment it did not work as expected. The installation seemed to proceed well, unfortunately though, when executing the example code I received the following error:

Compiling /home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/mujoco_py/cymj.pyx because it changed.
[1/1] Cythonizing /home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/mujoco_py/cymj.pyx
Traceback (most recent call last):
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/robohive/utils/import_utils.py", line 3, in mujoco_py_isavailable
import mujoco_py
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/mujoco_py/init.py", line 15, in
from mujoco_py.builder import cymj, ignore_mujoco_warnings, functions, MujocoException
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/mujoco_py/builder.py", line 499, in
cymj = load_cython_ext(mujoco_path)
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/mujoco_py/builder.py", line 106, in load_cython_ext
mod = load_dynamic_ext('cymj', cext_so_path)
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/mujoco_py/builder.py", line 125, in load_dynamic_ext
return loader.load_module()
ImportError: /home/lunet/cocp5/anaconda3/envs/robohiveRL04/bin/../lib/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /usr/lib/x86_64-linux-gnu/libLLVM-15.so.1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "robohive/utils/examine_env.py", line 110, in
main()
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/click/core.py", line 1130, in call
return self.main(*args, **kwargs)
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "robohive/utils/examine_env.py", line 55, in main
env = gym.make(env_name) if env_args==None else gym.make(env_name, **(eval(env_args)))
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/gym/envs/registration.py", line 156, in make
return registry.make(id, **kwargs)
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/gym/envs/registration.py", line 101, in make
env = spec.make(kwargs)
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/gym/envs/registration.py", line 73, in make
env = cls(
_kwargs)
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/robohive/envs/arms/reach_base_v0.py", line 41, in init
super().init(model_path=model_path, obsd_model_path=obsd_model_path, seed=seed)
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/robohive/envs/env_base.py", line 57, in init
self.sim = SimScene.get_sim(model_path)
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/robohive/physics/sim_scene.py", line 56, in get_sim
return SimScene.create(model_handle=model_handle, backend=SimBackend.MUJOCO_PY)
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/robohive/physics/sim_scene.py", line 42, in create
from robohive.physics import mjpy_sim_scene # type: ignore
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/robohive/physics/mjpy_sim_scene.py", line 15, in
import_utils.mujoco_py_isavailable()
File "/home/lunet/cocp5/anaconda3/envs/robohiveRL04/lib/python3.8/site-packages/robohive/utils/import_utils.py", line 11, in mujoco_py_isavailable
raise ModuleNotFoundError(f"{e}. {help}")
ModuleNotFoundError: /home/lunet/cocp5/anaconda3/envs/robohiveRL04/bin/../lib/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /usr/lib/x86_64-linux-gnu/libLLVM-15.so.1).
Options:
(1) follow setup instructions here: https://github.com/openai/mujoco-py/
(2) install mujoco_py via pip (pip install mujoco_py)
(3) install free_mujoco_py via pip (pip install free-mujoco-py)

I tried to create the conda environment and install RoboHive with all proposed pip install comands, both the ones for PyPi and the ones from the GitHub repository. Despite my efforts however, the same issue was always present.

As a final attempt I created an activate.sh file inside the bin folder of the conda environment that I was working on, and I appended at the end the same export commands to the ones I appended to the activate file of the venv environment. I also created an deactivate.sh in order to unset these environment variables when deactivating the environment. It did not work either ...

What is the real cause of this error and how can I overcome this?

It is important to note that the same issue was present both in my WSL2 Ubuntu 20.04.06 LTS system and in a native Linux Ubuntu 22.04 LTS workstation system.

I also wanted to inform you that I am working on the creation of the document that describes the setup procedure of my WSL2 setup where I am working with the RoboHive API, and I am planning to send it you as soon as possible!

Thank you very much in advance for your valuable help!!!

Kind regards,

Christos Peridis

@vikashplus
Copy link
Owner

Hi Christos,
Thanks for your interest and efforts on RoboHive.

From the error messages, it seems like mujoco_py installation issues. Can you try something like this to check if you have a healthy mujoco_py installation?

conda activate <env-name>
python -c "import mujoco_py"

Your first step will be to get above to succeed before attempting anything with RoboHive. Here are a few helpful resources to help you with mujoco_py

From the errors, it seems like an library issue. Pay attention to the following suggestions
sudo apt-get install libgl1-mesa-dev libgl1-mesa-glx libglew-dev libosmesa6-dev build-essential libglfw3

Alternatively, you can use RoboHive with MuJoCo's official bindings. Please refer to the RoboHive's installation FAQs for details on how to pick you simulation backend.

@vikashplus vikashplus added the good first issue Good for newcomers label Jul 6, 2023
@ChristosPeridis
Copy link
Author

Hello dear Dr. Vikash,

Thank you so much for your immediate response. Also thank you very much for your support material. I have tried the first approach and it did not work in the native Ubuntu machine at work. I am still working on it and I will also try the technique in my personal machine with the WSL2 set up. I will report back to you as soon as I have any updates!

Thank you very much for your valuable help!!!

Kind regards,

Christos Peridis

@ChristosPeridis
Copy link
Author

ChristosPeridis commented Jul 13, 2023

Hello dear Dr. Vikash,

How are you doing? I hope you are well! After a thorough research I managed to create two types of conda environments that where able to build and run mujoco-py and thus enabling me to test if RoboHive API is running, by running the example command : python robohive/utils/examine_env.py -e FrankaReachRandom-v0

as well as with the:

python -m robohive.utils.examine_env -e FrankaPickPlaceFixed-v0

which uses the environment that I am more interested in.

The first environment uses Python 3.8.10 build with gcc version 9.4.0, mujoco-py verion 2.0.2.13 and MuJoCo simulator version 200. It is important to note that Python 3.8.10 was required due to the version of gcc compiler being compatible with the abovementioned version of mujoco-py which is the latest version of the Python library which supports MuJoCo 200. In order to make the MuJoCo simulator visible to the environment I had to set the necessary environment varibles by running the "conda env config vars set " command. These where the following:

  1. conda env config vars set LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/.mujoco/mujoco200/bin

  2. conda env config vars set MUJOCO_PY_MJKEY_PATH=~/.mujoco/mjkey.txt

  3. conda env config vars set MUJOCO_PY_MUJOCO_PATH=~/.mujoco/mujoco200

The second environment uses Python 3.9.17 (which is more compatible with the RL APIs that I want to integrate RooHive API with) mujoco-py version 2.1.14 and MuJoCo simulator version 2.1.0 (210). For configuring this environment I followed step by step the instructions of the first link that you have provided me with. I just had to take one more extra step regarding the cython library which I upgraded to version 0.29.36. For installing the mujoco-py library I cloned the GitHub repository and built it from there, as it was the technique proposed by the PyTorch website. After following the main instructions on the PyTorch website I faced an issue with the GL/osmesa.h library. I overcome the issue by following the instructions that were bellow the main steps of setting up the environment, and were confronting the most frequent and most usual problems regarding the use of mujoco-py. Then I faced also an issue with the patchelf library. To overcome it once more I followed the instructions on the PyTorch website, and it fixed the issue. In this environment I further progressed trying to configuring it with Ray API and to make sure that all the core libraries do not have any conflicts. Due to the fact that I had been using pip, I had to perform many trial and error attempts of installing different versions of the necessary libraries, and sometimes when fixing one library another one was causing issues so I had to uninstall it and reinstall it.

I have exported the configuration of both environments in a .yml file for each and I will attach them to this message. For the python 3.9 environment I am sending you the configuration before and after installing Ray to the system, since the installation of Ray caused some inconsistencies.

The rhRL94_Ubuntu20_PY39_b_environment.yml is the file which contains the configuration of the conda environment with Python 3.9 before installing Ray. I have tested this file and it builds the environment with no pip issues. It only creates the environment for RoboHive with MuJoCo 2.1.0 and mujoco-py 2.1.14, with no Ray API.

The rhRL94_Ubuntu20_Py39_b_Ray220_a_environment.yml includes the dependencies after installing Ray and making the environment to work fine with not library errors due to incompatible versions. However when attempting to create the environment from the file it throughs a pip error. I guess, it is because of the order that the pip commands are executed.

The rhRL03_Ubuntu20_Py38_b_environment.yml crates the Python 3.8.10 environment with MuJoCo200 and mujoco-py=2.0.2.13 along with Ray API version 1.12.1. I have tested the also this .yml file and it builds the environment with no errors. However, before creating the environment one must add the following to the ~/.bashrc file:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH: ~/.mujoco/mujoco200/bin
export MUJOCO_PY_MJKEY_PATH= ~/.mujoco/mujoco200
export MUJOCO_PY_MJPRO_PATH= ~/.mujoco/mujoco200
export MUJOCO_PY_MJKEY_PATH= ~/.mujoco/mjkey.txt

After the installation of the environment from the .yml file one might have to uninstall mujoco-py and reinstall it (version 2.0.2.13) and uninstall the installed version ofprotobuf and install protobuf version 3.20.0.

In all scenarios one must also build the RoboHive package from the cloned GitHub repository, since this is the way I build it and installed it to the environments. This is why the .yml folders do not include the version of RoboHive installed.

These environments where created and tested on Ubuntu 20.04.06 LTS through WSL2 on Windows11.

For any further queries regarding the environments created through the provided .yml files do please let me know. I am always at your disposal!

General comment and recommendation for the RoboHive API is to move away from the mujoco-py library and star using only the mujo library with the newer Python bindings for the newer versions of MuJoCo simulator. This comes out as a result of my experience that I gained during the past few days where I tried to configure these environments. mujoco-py is difficult and time-consuming to setup and its configuration can go wrong very easily. Different version of MuJoCo support different versions of mujoco-py and specific versions of mujoco-py require specific builds of Python done by specific gcc compilers (for example in the case of mujoco-py==2.0.2.13 and python 3.8.10 which is build using gcc==9.4.0).

Thank you very much again for all the valuable help and support!!

Kind regards,

Christos Peridis

rhRL94_Ubuntu20_PY39_b_environment.zip
rhRL94_Ubuntu20_Py39_b_Ray220_a_environment.zip
rhRL03_Ubuntu20_Py38_b_environment.zip

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

No branches or pull requests

2 participants