dm_control icon indicating copy to clipboard operation
dm_control copied to clipboard

import MuJoCo, ImportError: cannot import name 'constants'

Open wwxFromTju opened this issue 8 years ago • 20 comments

Dear all: when I import MuJoCo, some error happen:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-7bf9adbdec98> in <module>()
----> 1 import dm_control.mujoco

/Users/codeMan/Documents/py-lab/dm_control/dm_control/mujoco/__init__.py in <module>()
     16 """Mujoco implementations of base classes."""
     17
---> 18 from dm_control.mujoco.engine import action_spec
     19
     20 from dm_control.mujoco.engine import Camera

/Users/codeMan/Documents/py-lab/dm_control/dm_control/mujoco/engine.py in <module>()
     41
     42 from dm_control import render
---> 43 from dm_control.mujoco import index
     44
     45 from dm_control.mujoco import wrapper

/Users/codeMan/Documents/py-lab/dm_control/dm_control/mujoco/index.py in <module>()
     92 # Internal dependencies.
     93
---> 94 from dm_control.mujoco.wrapper import util
     95 from dm_control.mujoco.wrapper.mjbindings import sizes
     96 import numpy as np

/Users/codeMan/Documents/py-lab/dm_control/dm_control/mujoco/wrapper/__init__.py in <module>()
     21
     22
---> 23 from dm_control.mujoco.wrapper import mjbindings
     24
     25 from dm_control.mujoco.wrapper.core import callback_context

/Users/codeMan/Documents/py-lab/dm_control/dm_control/mujoco/wrapper/mjbindings/__init__.py in <module>()
     22 from absl import logging
     23
---> 24 from dm_control.mujoco.wrapper.mjbindings import constants
     25 from dm_control.mujoco.wrapper.mjbindings import enums
     26 from dm_control.mujoco.wrapper.mjbindings import sizes

ImportError: cannot import name 'constants'

My python version is Python 3.5.3, and I use macOs sierra 10.12.6

wwxFromTju avatar Jan 04 '18 11:01 wwxFromTju

Did you install making it editable? This gave me the same problem. In other words, this doesn't work

pip install -e <path_to_dm_control>

while this does work

pip install <path_to_dm_control>

I tend to always use the former when trying out new libraries, so I can edit them and see how they work. However, if you make the library editable, it doesn't seem to generate the needed mjbindings.

efagerho avatar Jan 04 '18 13:01 efagerho

@efagerho you mean install?

wwxFromTju avatar Jan 04 '18 13:01 wwxFromTju

@wwxFromTju: Yes. Fixed it.

efagerho avatar Jan 04 '18 14:01 efagerho

@efagerho It also have this err. can't solve it.

wwxFromTju avatar Jan 04 '18 14:01 wwxFromTju

Hi @wwxFromTju it sounds like the ctypes wrappers may not have been generated for some reason. If everything ran successfully, you should see constants.py (and others imported in init.py) in /Users/codeMan/Documents/py-lab/dm_control/dm_control/mujoco/wrapper/mjbindings/. How did you install the package the first time?

yotam avatar Jan 04 '18 16:01 yotam

@yotam now, I create a clean conda env to install it, fix this problem.

wwxFromTju avatar Jan 04 '18 16:01 wwxFromTju

Thanks for the update. I'm going to close the issue, though if you run into it again do reopen. @efagerho I believe the -e install failed due to the way the output directory is determined here. We'll look into making this more flexible.

yotam avatar Jan 04 '18 16:01 yotam

hi @wwxFromTju Which python version do you use?

andrewliao11 avatar Jan 07 '18 11:01 andrewliao11

@akfidjeland I try 3.6 and 3.5.

wwxFromTju avatar Jan 16 '18 11:01 wwxFromTju

I am working with Python 2.7 and it is not working for me. Still, I am using pip install <path to dm_control> It would still give me

>>> from dm_control import suite
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "dm_control/suite/__init__.py", line 28, in <module>
    from dm_control.suite import acrobot
  File "dm_control/suite/acrobot.py", line 26, in <module>
    from dm_control import mujoco
  File "dm_control/mujoco/__init__.py", line 18, in <module>
    from dm_control.mujoco.engine import action_spec
  File "dm_control/mujoco/engine.py", line 43, in <module>
    from dm_control.mujoco import index
  File "dm_control/mujoco/index.py", line 94, in <module>
    from dm_control.mujoco.wrapper import util
  File "dm_control/mujoco/wrapper/__init__.py", line 23, in <module>
    from dm_control.mujoco.wrapper import mjbindings
  File "dm_control/mujoco/wrapper/mjbindings/__init__.py", line 24, in <module>
    from dm_control.mujoco.wrapper.mjbindings import constants
ImportError: cannot import name constants
>>>

HenryZhou7 avatar Jan 22 '18 01:01 HenryZhou7

@wwxFromTju What is a clean conda environment has to do with the installation? I thought the installation of dm_control is pretty much isolated from conda environment?

HenryZhou7 avatar Jan 22 '18 01:01 HenryZhou7

@HenryZhou7 create a new environment

wwxFromTju avatar Jan 24 '18 00:01 wwxFromTju

Hi @wwxFromTju it sounds like the ctypes wrappers may not have been generated for some reason. If everything ran successfully, you should see constants.py (and others imported in init.py) in /Users/codeMan/Documents/py-lab/dm_control/dm_control/mujoco/wrapper/mjbindings/. How did you install the package the first time?

I have the same problem. Why dont I see the constants.py under \mujoco\wrapper\mjbindings ?

nilaytufek avatar Sep 24 '18 16:09 nilaytufek

@HenryZhou7 In the initial conda environment, I have installed some python packages. So there may be some version number issues.

wwxFromTju avatar Sep 25 '18 04:09 wwxFromTju

@nilaytufek create a new conda env

wwxFromTju avatar Sep 25 '18 05:09 wwxFromTju

@nilaytufek create a new conda env

no, "new conda env" did now work for me. But, anyway, I soved my problem. I copied all under "C:\ProgramData\Anaconda3\Lib\site-packages\dm_control\mujoco" under <your_local_git_clone>\dm_control\mujoco .. That woked for me.

nilaytufek avatar Sep 27 '18 10:09 nilaytufek

This happens if you "pip install" but then try to import the module form the github source dir. change to some other path than the github checkout and it will work.

powderluv avatar Apr 06 '19 04:04 powderluv

@powderluv Thanks! Didn't realize that was another potential source of error.

DanielTakeshi avatar May 10 '19 23:05 DanielTakeshi

Because the name of lib "dm_control" is same to the dir "dm_control" and "dm_control/dm_control", it cite the dir's "constants",but there does not have it . I rename the dir's name to solve the problem.

FrankJIE09 avatar Dec 29 '21 11:12 FrankJIE09

@FrankJIE09 changing the name of the directory worked. I changed it from dm_control to dm_control1 and then ran the code and it worked. Thanks!

Aakash-Kots1 avatar Oct 08 '24 18:10 Aakash-Kots1