Pregunta instalando Mayavi con pip - ningún módulo llamado vtk


Quiero usar Mayavi.

Situación

  • Uso MacBook Air, con OSX 10.7.3.
  • Yo uso Python 2.7.2
  • yo tengo virtualenv instalado Pero no lo he usado para esta instalación.

He instalado manualmente todas sus dependencias, incluidas VTK.

por VTK, Seguí su guía de instalación e instalé el contenedor de Python.

Ahora si abro una nueva ventana de terminal y abro Python, puedo importar vtk sin ningún error

Problema

Intento instalar Mayavi con el siguiente comando:

pip install mayavi

Pero ocurre el siguiente error:

Downloading/unpacking mayavi
  Running setup.py egg_info for package mayavi
    build_src
    building extension "tvtk.array_ext" sources
    building data_files sources
    build_src: building npy-pkg config files

    no previously-included directories found matching 'artwork'
    no previously-included directories found matching 'docs/pdf'
Requirement already satisfied (use --upgrade to upgrade): apptools in /Library/Python/2.7/site-packages (from mayavi)
Requirement already satisfied (use --upgrade to upgrade): traits in /Library/Python/2.7/site-packages (from mayavi)
Requirement already satisfied (use --upgrade to upgrade): traitsui in /Library/Python/2.7/site-packages (from mayavi)
Requirement already satisfied (use --upgrade to upgrade): configobj in /Library/Python/2.7/site-packages (from apptools->mayavi)
Requirement already satisfied (use --upgrade to upgrade): pyface in /Library/Python/2.7/site-packages (from traitsui->mayavi)
Installing collected packages: mayavi
  Running setup.py install for mayavi
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/Users/Yasser/build/mayavi/setup.py", line 498, in <module>
        **config
      File "/Library/Python/2.7/site-packages/numpy-1.6.1-py2.7-macosx-10.7-intel.egg/numpy/distutils/core.py", line 186, in setup
        return old_setup(**new_attr)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup
        dist.run_commands()
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/Library/Python/2.7/site-packages/numpy-1.6.1-py2.7-macosx-10.7-intel.egg/numpy/distutils/command/install.py", line 57, in run
        r = self.setuptools_run()
      File "/Library/Python/2.7/site-packages/numpy-1.6.1-py2.7-macosx-10.7-intel.egg/numpy/distutils/command/install.py", line 31, in setuptools_run
        return old_install_mod._install.run(self)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/install.py", line 573, in run
        self.run_command('build')
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
        self.distribution.run_command(command)
      File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
        cmd_obj.run()
      File "/Users/Yasser/build/mayavi/setup.py", line 303, in run
        build_tvtk_classes_zip()
      File "/Users/Yasser/build/mayavi/setup.py", line 290, in build_tvtk_classes_zip
        gen_tvtk_classes_zip()
      File "tvtk/setup.py", line 46, in gen_tvtk_classes_zip
        from code_gen import TVTKGenerator
      File "tvtk/code_gen.py", line 10, in <module>
        import vtk
    ImportError: No module named vtk
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/Users/Yasser/build/mayavi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /var/folders/53/_trhc_0x0fb6kvx6bw_wrk500000gn/T/pip-Z4hpsW-record/install-record.txt:
    running install

running build

Traceback (most recent call last):

  File "<string>", line 1, in <module>

  File "/Users/Yasser/build/mayavi/setup.py", line 498, in <module>

    **config

  File "/Library/Python/2.7/site-packages/numpy-1.6.1-py2.7-macosx-10.7-intel.egg/numpy/distutils/core.py", line 186, in setup

    return old_setup(**new_attr)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup

    dist.run_commands()

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands

    self.run_command(cmd)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command

    cmd_obj.run()

  File "/Library/Python/2.7/site-packages/numpy-1.6.1-py2.7-macosx-10.7-intel.egg/numpy/distutils/command/install.py", line 57, in run

    r = self.setuptools_run()

  File "/Library/Python/2.7/site-packages/numpy-1.6.1-py2.7-macosx-10.7-intel.egg/numpy/distutils/command/install.py", line 31, in setuptools_run

    return old_install_mod._install.run(self)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/install.py", line 573, in run

    self.run_command('build')

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command

    self.distribution.run_command(command)

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command

    cmd_obj.run()

  File "/Users/Yasser/build/mayavi/setup.py", line 303, in run

    build_tvtk_classes_zip()

  File "/Users/Yasser/build/mayavi/setup.py", line 290, in build_tvtk_classes_zip

    gen_tvtk_classes_zip()

  File "tvtk/setup.py", line 46, in gen_tvtk_classes_zip

    from code_gen import TVTKGenerator

  File "tvtk/code_gen.py", line 10, in <module>

    import vtk

ImportError: No module named vtk

----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/Users/Yasser/build/mayavi/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /var/folders/53/_trhc_0x0fb6kvx6bw_wrk500000gn/T/pip-Z4hpsW-record/install-record.txt failed with error code 1 in /Users/Yasser/build/mayavi
Storing complete log in /Users/Yasser/Library/Logs/pip.log
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 8, in <module>
    load_entry_point('pip==1.1', 'console_scripts', 'pip')()
  File "/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg/pip/__init__.py", line 116, in main
    return command.main(args[1:], options)
  File "/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 141, in main
    log_fp = open_logfile(log_fn, 'w')
  File "/Library/Python/2.7/site-packages/pip-1.1-py2.7.egg/pip/basecommand.py", line 168, in open_logfile
    log_fp = open(filename, mode)
IOError: [Errno 13] Permission denied: '/Users/Yasser/Library/Logs/pip.log'

Creo que el problema es con vtk.

¿Alguien puede ayudarme?

Otros detalles

Corriendo sudo pip install mayavi no resuelve el problema

Pensé que esto podría ayudar

› which python
/usr/local/bin/python

› python
Python 2.7.2 (default, Feb 17 2012, 13:57:55) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import vtk
>>> vtk
<module 'vtk' from '/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/VTK-5.10.0-py2.7.egg/vtk/__init__.pyc'>
>>> 

Mi PYTHONPATH esta vacio.


28
2017-08-29 16:03


origen


Respuestas:


Tu pip es probable que esté usando un diferente python, tipo de ti vtk instalado usando /usr/local/bin/python, mientras tu pip usos binarios /usr/bin/python.

Revisalo:

$ head -n1 $(which pip)

Para solucionarlo, puede elegir usar un virtualenv, o instalar pip utilizando /usr/local/bin/python:

curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | /usr/local/bin/python

Para obtener más instrucciones de instalación, consulte http://www.pip-installer.org/en/latest/installing.html


10
2017-08-30 23:09



Estoy en Debian, pero esto también debería funcionar para ti

Me quedé con la instalación de vtk en un virtualenv, después de horas de búsqueda sin resultados, hice lo siguiente y funcionó.

  1. instalar python-vtk desde los repositorios de todo el sistema

  2. copiar la carpeta vtk de /usr/lib/pymodules/python2.7 a /PATH/TO/YOUR/VIRTUALENV/lib/python2.7/site-packages

En su caso, la carpeta de paquetes de python para todo el sistema probablemente sea diferente, pero puede encontrarla fácilmente activando el sistema python e ingresando lo siguiente:

import vtk,sys
print(sys.modules['vtk'])

Después de este truco mayavi se instaló con éxito en mi virtualenv usando pip install mayavi y pip install vision.

Editar: en lugar de copiar, sería mejor que vincules simbólicamente la carpeta en el paso 2


16
2018-06-30 19:34



Tuve el mismo problema y la primera respuesta no me ayudó porque pip estaba en el directorio correcto, pero resultó que no tenía vtk instalado. Al ejecutar sudo apt-get install python-vtk se solucionó el problema y pude para ejecutar con éxito pip install mayavi después de eso.


8
2018-05-18 00:08



Tuve el mismo problema al instalar mayavi con python instalado en pyenv, y resolví este problema al copiar el directorio a /home/myname/.pyenv/versions/2.7.12/lib/python2.7/site-packagesA continuación, mi método:

  1. instalar vtk y python-vtk

    sudo apt-get install vtk6
    sudo apt-get install python-vtk
    
  2. tratar python -c "import vtk", si falla nuevamente, vaya al paso 3

  3. el error de importación puede ser causado por la pérdida de la carpeta del paquete vtk en su python actual, por lo que deberíamos encontrar la carpeta vtk y copiarla en su directorio python actual (la más posible es el python en pyenv shims directory).

    la ruta de la carpeta vtk en mi ubuntu es

    /usr/lib/python2.7/dist-packages/vtk
    

    solo copia el vtk carpeta a su python actual /site-packages, p.ej.

    cp -r /usr/lib/python2.7/dist-packages/vtk /home/myname/pyenv/versions/2.7.12/lib/python2.7/site-packages
    
  4. tratar python -c "import vtk" de nuevo.

  5. si no hay error de importación, solo hazlo

    pip install mayavi
    

3
2017-09-19 14:13



Insistí en sudo instalar por varias veces, finalmente se resolvió, no sé cómo explicar.

sudo python2 -m pip install mayavi

sudo python3 -m pip install mayavi

0
2018-06-25 20:59



Instalé vtk usando Homebrew:

$ brew install vtk

espero que esto ayude.


-1
2017-10-27 19:03