installing Mayavi with pip - no module named vtk

前端 未结 6 1991
耶瑟儿~
耶瑟儿~ 2020-12-24 11:48

I want to use Mayavi.

Situation

  • I use a MacBook Air, with OSX 10.7.3.
  • I use Python 2.7.2
  • I have virtualenv installed.
相关标签:
6条回答
  • 2020-12-24 12:25

    I insisted in sudo install for several times, finally got solved, don't know how to explain.

    sudo python2 -m pip install mayavi
    
    sudo python3 -m pip install mayavi
    

    UPDATE

    I can't install via pip for laptop. Then I install the latest mayavi by

    git clone https://github.com/enthought/mayavi.git
    cd mayavi
    pip install -r requirements.txt
    pip install PyQt5  # replace this with any supported toolkit
    python setup.py install  # or develop
    

    after installation. Test with

    mayavi2
    

    Then report say couldn't find module PyQt5.Qtsvg, so

    sudo apt install python3-pyqt5.qtsvg
    

    Now it works.

    0 讨论(0)
  • 2020-12-24 12:29

    Your pip is probably using a different python, kind of you have vtk installed using /usr/local/bin/python, while your pip binary uses /usr/bin/python.

    Check it:

    $ head -n1 $(which pip)
    

    In order to get it solved, you can choose to use a virtualenv, or install pip using /usr/local/bin/python:

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

    For more installation instructions, see http://www.pip-installer.org/en/latest/installing.html

    0 讨论(0)
  • 2020-12-24 12:29

    I had the same problem when installing mayavi with python installed in pyenv, and I solved this problem by copy directory to /home/myname/.pyenv/versions/2.7.12/lib/python2.7/site-packages, below is my method:

    1. install vtk and python-vtk

      sudo apt-get install vtk6
      sudo apt-get install python-vtk
      
    2. try python -c "import vtk", if failed again, go to step 3

    3. the import error may caused by the loss of vtk package folder in your current python, so we should find the vtk folder and copy to your current python(most possible the python in pyenv shims directory)'s directory .

      the path of the vtk folder in my ubuntu is

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

      just copy the vtk folder to your current python's /site-packages, e.g.

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

    5. if no import error, just do

      pip install mayavi
      
    0 讨论(0)
  • 2020-12-24 12:30

    I had the same problem and the first answer didn't help me because pip was in the right directory, but it turned out I didn't have vtk installed - running sudo apt-get install python-vtk fixed the issue and I was able to successfully run pip install mayavi after that.

    0 讨论(0)
  • 2020-12-24 12:39

    I'm on Debian but this should work for you as well

    I was stuck with installing vtk into a virtualenv, after hours of search with no results I did the following and it worked.

    1. install python-vtk from repositories systemwide

    2. copy vtk folder from /usr/lib/pymodules/python2.7 to /PATH/TO/YOUR/VIRTUALENV/lib/python2.7/site-packages

    In your case the system-wide python packages folder would probably be different but you can easily find it by firing up system python and entering the following:

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

    After this trick mayavi was succesfully installed into my virtualenv using pip install mayavi and pip install envisage.

    Edit: instead of copying it might better to just symlink the folder in step 2

    0 讨论(0)
  • I installed vtk using Homebrew:

    $ brew install vtk
    

    hope this helps.

    0 讨论(0)
提交回复
热议问题