Question

I've encountered a very strange error when trying to Import mayavi. A few minutes ago it worked like a charm, but now there's something going wrong and I've no clue why.

I start python from the terminal and then I type:

from mayavi import mlab

The error I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/mayavi/mlab.py", line 27, in <module>
    from mayavi.tools.camera import view, roll, yaw, pitch, move
  File "/usr/lib/python2.7/dist-packages/mayavi/tools/camera.py", line 23, in <module>
    from engine_manager import get_engine
  File "/usr/lib/python2.7/dist-packages/mayavi/tools/engine_manager.py", line 14, in <module>
    from mayavi.core.engine import Engine
  File "/usr/lib/python2.7/dist-packages/mayavi/core/engine.py", line 28, in <module>
    from mayavi.core.scene import Scene
  File "/usr/lib/python2.7/dist-packages/mayavi/core/scene.py", line 15, in <module>
    from mayavi.core.source import Source
  File "/usr/lib/python2.7/dist-packages/mayavi/core/source.py", line 19, in <module>
    from mayavi.core.module_manager import ModuleManager
  File "/usr/lib/python2.7/dist-packages/mayavi/core/module_manager.py", line 19, in <module>
    from mayavi.core.lut_manager import LUTManager
  File "/usr/lib/python2.7/dist-packages/mayavi/core/lut_manager.py", line 10, in <module>
    import subprocess
  File "/usr/lib/python2.7/subprocess.py", line 432, in <module>
    import pickle
  File "pickle.py", line 4, in <module>
    from mayavi import mlab
ImportError: cannot import name mlab

What's wrong with Python?

Was it helpful?

Solution

You have a local file named pickle.py; this is being imported instead of the pickle module. This module then tries to import mlab before that module itself has completed importing in a circular import dependency:

  File "/usr/lib/python2.7/subprocess.py", line 432, in <module>
    import pickle
  File "pickle.py", line 4, in <module>
    from mayavi import mlab

Note how subprocess tries to import pickle and finds your file instead (the path is relative instead of a full path inside /usr/lib/python2.7/.

Rename pickle.py to something else, you are masking the standard library here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top