ImportError: No module named vtkCommonPython

前端 未结 8 972
不思量自难忘°
不思量自难忘° 2020-12-06 09:34

I am trying to install Python with VTK on my computer, but when I want to import VTK, I get an error:

import vtk 
Traceback (most recent call last): 
 File          


        
相关标签:
8条回答
  • 2020-12-06 10:14

    I was having the same problem (kubuntu 14.04).

    I realized that the links to the compiled vtkpython objects in /usr/lib/python2.7/dist-packages/vtk were broken.

    So I went to /usr/lib/x86_64-linux-gnu and ran for i in *-6.0.so.6.0; do sudo ln -s $i ${i/-6.0.so.6.0/-6.0.so}; done.

    It seemed to solve the issue.

    Hope that helps.

    0 讨论(0)
  • 2020-12-06 10:26

    It needs to be in the directory of the sys.path. What I did is I created a folder (doesn't really matter where) called "Modules" in which I have all of my modules that I download/create in there. Say I put it in C:\Users\USER\Modules. You can put this module in there as well.

    You need to copy the path to the folder.

    Then, go to Control Panel. Click System, then on the left panel there is an option called "Advanced System Settings". Click that. From the bottom of the window that pops up, click "Environment Variables". Look to see if you have a variable created called PYTHONPATH. Most likely, you don't. So, create a variable (in the second section) by pressing "NEW". Name it PYTHONPATH and for the Variable value, put in the file path. (For my example, the file path is C:\Users\USER\Modules). Hope this helps :)

    I inserted a screenshot of how to get there once you get to the System (Properties) location in Control Panel: Python Path

    0 讨论(0)
  • 2020-12-06 10:28

    I was having this same problem on MacOSX. So I started using vtk/bin/vtkpython instead of python. This allowed me to import vtk without any errors. I then imported vtkCommonCorePython explicitly and printed the location:

    $ /home/vtk/bin/vtkpython
    vtk version 6.2.0
    Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import vtkCommonCorePython 
    >>> print vtkCommonCorePython
    <module 'vtkCommonCorePython' from '/home/vtk/lib/vtkCommonCorePython.so'>
    

    In the terminal, I then added the lib folder to my python virtual environment path:

    $ add2virtualenv /home/vtk/lib
    

    I don't know how this would translate to Windows, but I hope this helps!

    0 讨论(0)
  • 2020-12-06 10:29

    I ran into a very similar problem, and fixed it by adding /usr/local/lib/python2.7/site-packages/vtk/ to the PYTHONPATH environment variable.

    Your exact fix may vary depending on your version of python, etc (it affects the paths). You should be able to sort it out by locating the location of the missing module and then adding the path to the environment variable as follows.

    In my case, I found the path using:

    find / -name vtkCommonCorePython 2>/dev/null
    

    And then added the relevant path to ~/.bash_rc or equivalent.

    export PYTHONPATH="$PYTHONPATH:usr/local/lib/python2.7/site-packages/vtk/"
    

    Be careful that you append to the path variable rather than overwriting it - you probably already need to have some other stuff like '/usr/local/lib/' in there. The format (and file where you put this!) is different for different shells.

    Restart the terminal to get the changes through, and then check that the variable is set up correctly:

    echo $PYTHONPATH
    

    And be very careful that there are no mistakes in any of the paths!

    0 讨论(0)
  • 2020-12-06 10:32

    In windows,

    You are supposed to add the following path
    Add the folders containing the .pyd and .dll files to the PYTHONPATH environment variable.

    Example:

    D:\VTK\VTK-bin\bin\Release\Lib\site-packages\vtkmodules
    D:\VTK\VTK-bin\bin\Release

    Additionally, add the path to bin folder of Qt to the System variable PATH C:\Qt\5.10.0\msvc2017_64\bin

    0 讨论(0)
  • 2020-12-06 10:33

    Apart from checking that vtk is inside your $PYTHONPATH, also note that more recent versions of VTK (6.x) no longer have a vtkCommonPython module. Instead it has been split into several sub-components. (e.g. vtkCommonCorePython, vtkCommonMathPython, vtkCommonSystemPython), but this will mostly be a problem for external packages you might want to use (e.g. VMTK is by default compiled against and dependend upon VTK 5.10.

    To check and expand your $PYTHONPATH simply call:

    $ echo $PYTHONPATH
    /usr/local/lib/python2.7/site-packages
    $ export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages/vtk
    $ echo $PYTHONPATH
    /usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/site-packages/vtk
    

    To check which vtk version you have installed:

    $ python
    Python 2.7.10
    >>> import vtk
    >>> print str(vtk.VTK_MAJOR_VERSION) + '.' + str(vtk.VTK_MINOR_VERSION)
    6.2
    
    0 讨论(0)
提交回复
热议问题