google-deepmind / dm_control

Google DeepMind's software stack for physics-based simulation and Reinforcement Learning environments, using MuJoCo.
Apache License 2.0
3.75k stars 665 forks source link

I installed it without -e option, but I got cannot import name 'constants' error. #390

Open Ishihara-Masabumi opened 1 year ago

Ishihara-Masabumi commented 1 year ago

I tried to install this repository as follows:

git clone https://github.com/deepmind/dm_control.git
cd dm_control/
pip3 install -r requirements.txt 

But, after running the command, the following error occurred.

python3 ./dm_control/locomotion/soccer/explore.py
ImportError: cannot import name 'constants' from partially initialized module 'dm_control.mujoco.wrapper.mjbindings' (most likely due to a circular import) (/home/dl/DM_Control2/dm_control/dm_control/mujoco/wrapper/mjbindings/__init__.py)

Please let me know how to avoid it.

metric-space commented 1 year ago

~Try not running the command from the root directory~ This is what worked for me python3 -mvenv dm_control cd dm_control && source bin/activate && pip install . && pip install pillow && python ./locomotion/soccer/explore.py

raymondchua commented 6 months ago

I have the same error as @Ishihara-Masabumi as well. Does anyone know how to overcome it? The solution proposed by @metric-space did not work for me.

Yang6852 commented 6 months ago

I also have this problem and haven't found a solution yet

metric-space commented 6 months ago

@raymondchua I did a fresh install just now and changed the bash command I put on here earlier (included pillow install and changed the proper url). This was on arch linux and I have it working. Please try with the edited commands

metric-space commented 6 months ago

Something to remember is pip install . activates setup.py and does a lot more (and including) than just install dependencies via pip install -r requirements.txt

raymondchua commented 6 months ago

Thanks @metric-space. The error shows up when I try to run the following code:

from dm_control import suite
env = suite.load('cartpole', 'swingup')
pixels = env.physics.render()
raymondchua commented 6 months ago

Specifically, the import statement is causing the error:

from dm_control import suite

raymondchua commented 6 months ago

Ok, after some playing and digging around, @metric-space is right. After git clone the repo, we need to pip install . If I am not wrong, if you make any changes in your local repo, you will need to pip install . for those changes to be reflected. pip install . is actually critical as it creates the following files in the mjbindings folder: constants.py, enums.py and sizes.py. With these steps, I am now able to run from dm_control import suite without any error.