installing Mayavi with pip - no module named vtk

萝らか妹 提交于 2019-11-29 23:52:43

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

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

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.

PytLab

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
    

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

I installed vtk using Homebrew:

$ brew install vtk

hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!