ImportError: cannot import name PoppyHumanoid

Hi all,

I had VREP working like a charm, but now when I try to initiate a poppy, I get this error:

Jean-michels-MacBook-Pro:functions jmm$ python import.py 
Traceback (most recent call last):
  File "import.py", line 1, in <module>
    from poppy.creatures import PoppyHumanoid
  File "/Library/Python/2.7/site-packages/poppy/creatures/__init__.py", line 1, in <module>
    from abstractcreature import AbstractPoppyCreature
  File "/Library/Python/2.7/site-packages/poppy/creatures/abstractcreature.py", line 4, in <module>
    from pypot.robot import Robot, from_json
  File "/usr/local/lib/python2.7/site-packages/pypot-2.2.1-py2.7.egg/pypot/robot/__init__.py", line 1, in <module>
    from .robot import Robot
  File "/usr/local/lib/python2.7/site-packages/pypot-2.2.1-py2.7.egg/pypot/robot/robot.py", line 3, in <module>
    from ..primitive.manager import PrimitiveManager
  File "/usr/local/lib/python2.7/site-packages/pypot-2.2.1-py2.7.egg/pypot/primitive/__init__.py", line 1, in <module>
    from .primitive import Primitive, LoopPrimitive
  File "/usr/local/lib/python2.7/site-packages/pypot-2.2.1-py2.7.egg/pypot/primitive/primitive.py", line 3, in <module>
    import numpy
  File "/usr/local/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
    from . import add_newdocs
  File "/usr/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 46, in <module>
    from numpy.testing import Tester
  File "/usr/local/lib/python2.7/site-packages/numpy/testing/__init__.py", line 13, in <module>
    from .utils import *
  File "/usr/local/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in <module>
    from tempfile import mkdtemp
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in <module>
    from random import Random as _Random
  File "/Users/jmm/Documents/code/prog/Poppy/functions/random.py", line 1, in <module>
    from poppy.creatures import PoppyHumanoid
ImportError: cannot import name PoppyHumanoid

where the python script include only this:

from poppy.creatures import PoppyHumanoid
poppy = PoppyHumanoid(simulator='vrep')

I uninstalled and re-installed pypot + poppy_humanoid to no avail.

Using this:

from pypot.vrep import from_vrep
from poppy.creatures import PoppyHumanoid

gives me similar error (but cannot import robot etc.)

Any thoughts?

1 Like

Can you try to run the following code:

from poppy_humanoid import PoppyHumanoid

done that, no errors. I don’t think the problem is in the lib (or absence thereof). Somehow it seems the function get’s called twice…

If you can run this line, the lib is installed correctly.

Something that could really mess everything up is that you named your python file import.py. This could (I’m not sure it’s here the problem, but in any case this is a bad idea) mix up with the import statement of python.

Let me know if changing the name helps.

Whatever file I run (and I tried files that worked before) I get the same result. I just tried to run the first two lines in ipython though, and I’m getting a VrepConnectionError… so if I try and stop any still open connections, I get a name ‘pypot’ is not defined…

Must be something really stupid :slight_smile:

I “guess” you try do directly run

pypot.vrep.close_all_connections()

Before doing that you have to do

import pypot.vrep

For this

ImportError: cannot import name PoppyHumanoid

Indeed, it seems that there is a bug when importing multiple times PoppyHumanoid. I’ll try to fix it soon. Yet, in the meantime, as you already imported this module, you shouldn’t need to re-import it, you could also just try catch the error and it won’t cause anymore problem.

If I do, that, I get a

ImportError: cannot import name Robot

and

gives me
name ‘pypot’ is not defined.

I think it’s a linkage problem with vrep, not pypot and/or multiple imports.

Ok, so if I add a copy of the class poppy_humanoid, and I try and import that class

from poppy.creatures import PoppyHumanoid_new

I still get a

ImportError: cannot import name PoppyHumanoid

So there is an issue with it getting imported 2 times…

But from where? Does random.py import an instance?

It looks like a recursive import issue. I know there is some in pypot/poppy I’ll try to fix them.

Can you post the entire code you are running because I cannot reproduce your bug on my machine.

If I run this:

from poppy_humanoid import PoppyHumanoid

I get this:

>>> from poppy_humanoid import PoppyHumanoid
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/poppy_humanoid/__init__.py", line 1, in <module>
    from poppy_humanoid import PoppyHumanoid
  File "/usr/local/lib/python2.7/site-packages/poppy_humanoid/poppy_humanoid.py", line 1, in <module>
    import numpy
  File "/usr/local/lib/python2.7/site-packages/numpy/__init__.py", line 170, in <module>
    from . import add_newdocs
  File "/usr/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 46, in <module>
    from numpy.testing import Tester
  File "/usr/local/lib/python2.7/site-packages/numpy/testing/__init__.py", line 13, in <module>
    from .utils import *
  File "/usr/local/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in <module>
    from tempfile import mkdtemp
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 35, in <module>
    from random import Random as _Random
  File "random.py", line 1, in <module>
    from poppy.creatures import PoppyHumanoid
  File "/Library/Python/2.7/site-packages/poppy/creatures/__init__.py", line 1, in <module>
    from abstractcreature import AbstractPoppyCreature
  File "/Library/Python/2.7/site-packages/poppy/creatures/abstractcreature.py", line 4, in <module>
    from pypot.robot import Robot, from_json
  File "/usr/local/lib/python2.7/site-packages/pypot/robot/__init__.py", line 1, in <module>
    from .robot import Robot
  File "/usr/local/lib/python2.7/site-packages/pypot/robot/robot.py", line 3, in <module>
    from ..primitive.manager import PrimitiveManager
  File "/usr/local/lib/python2.7/site-packages/pypot/primitive/manager.py", line 13, in <module>
    class PrimitiveManager(StoppableLoopThread):
  File "/usr/local/lib/python2.7/site-packages/pypot/primitive/manager.py", line 21, in PrimitiveManager
    def __init__(self, motors, freq=50, filter=partial(numpy.mean, axis=0)):
AttributeError: 'module' object has no attribute 'mean'

Did you create a file named random.py in your current directory?
You should really try to avoid naming your python script with “standard” names.

Did not, but I have that file indeed… very strange, I must have done something stupid…

This topic was automatically closed after 24 hours. New replies are no longer allowed.