4

I've installed vtk from vtkpython-6.3.0-Windows-64bit.exe in C:\Program Files\VTK 6.3.0 of my computer. Then I add C:\Program Files\VTK 6.3.0\bin to my Path and C:\Program Files\VTK 6.3.0\bin as well as C:\Program Files\VTK 6.3.0\bin\Lib\site-packages to my PYTHONPATH in system variables. When I run IDLE (Python GUI).exe of Python and input import vtk,it shows:

>>> import vtk
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import vtk
  File "C:\Program Files\VTK 6.3.0\bin\Lib\site-packages\vtk\__init__.py",   line 39, in <module>
    from vtkCommonCore import *
ImportError: No module named 'vtkCommonCore'
>>> 

What mistake did I make?

Please help me of this.

Richard.L
  • 139
  • 3
  • 14
  • Please post the text of your error message (not an image). – Jon Surrell Jan 25 '16 at 16:57
  • It looks like VTK embeds Python. Is running it through a system Python actually supported? – Eryk Sun Jan 25 '16 at 17:38
  • @eryksun :Sorry,what do you mean by a system Python? I installed WinPython in my computer , Windows system. I think vtk can work on Python,but I don't know what mistake I've made. – Richard.L Jan 26 '16 at 13:16
  • By embed I mean it looks like there should be an executable in the `bin` directory that links with pythonXY.dll (e.g. python27.dll), probably located in the same directory, and looks for a standard library (possibly modified) in `bin\Lib`, with VTK packages installed under `bin\Lib\site-packages`. I'm not saying it can't be used the way you want to. This is just a passing observation, plus I'm wondering why you're not using it as a standalone package. – Eryk Sun Jan 26 '16 at 13:57
  • 1
    @eryksun: Well, my tutor asked me to use Python 3 to generate sea surface with VTK library. I'm sorry that my English is very poor, so I can't understand what you mean clearly :( Thank you very much for your instruction. – Richard.L Jan 26 '16 at 14:27

3 Answers3

4

Are you sure that you set the environment variables correctly? For example , be careful with quotes (aka don't put them).

I installed VTK 7 in Y instead that in program files (probably not a good choice since the built in vtkpython doesn't work), and the following setting for me works:

C:\Users\lib>set PATH=Y:\VTK 7.0.0-RC2\bin;%PATH%

C:\Users\lib>set PYTHONPATH=Y:\VTK 7.0.0-RC2\bin\Lib\site-packages

C:\Users\lib>python -c "import vtk;print vtk.__file__;print vtk.vtkVersion().GetVTKVersion()"
Y:\VTK 7.0.0-RC2\bin\Lib\site-packages\vtk\__init__.pyc
7.0.0

In case of problems, try to add also C:\Program Files\VTK 6.3.0\bin\Lib\site-packages\vtk to PATH (there are dlls in it as well)

lib
  • 2,918
  • 3
  • 27
  • 53
  • 1
    I'm not sure. I did nothing with the user variables, but add `C:\Program Files\VTK 6.3.0\bin` `C:\Program Files\VTK 6.3.0\bin\Lib\site-packages` `C:\Program Files\VTK 6.3.0\bin\Lib\site-packages\vtk` to both PATH and PYTHONPATH . But it still doesn't work. Should I download `cmake` or something? I saw this on the internet,it says Visual Studio is needed,but I just want to use vtk in WinPython of my computer.@lib – Richard.L Jan 26 '16 at 13:11
  • Are you using ; to separate the paths? Cmake and visual studio are needed to compile vtk on you own, so in your case it's not necessary – lib Jan 26 '16 at 13:13
  • Yes, I used ; to seperate . – Richard.L Jan 26 '16 at 13:18
  • By the way, PYTHONPATH did not exist in my system variables before,but I new PYTHONPATH by myself and add the words in it. – Richard.L Jan 26 '16 at 13:19
  • After I add `C:\Program Files\VTK 6.3.0\bin\Lib\site-packages\vtk` to PATH and PYTHONPATH ,the error change to this :`import vtk Traceback (most recent call last): File "", line 1, in import vtk File "C:\Program Files\VTK 6.3.0\bin\Lib\site-packages\vtk\__init__.py", line 39, in from vtkCommonCore import * File "C:\Program Files\VTK 6.3.0\bin\Lib\site-packages\vtk\vtkCommonCore.py", line 1, in from vtkCommonCorePython import * ImportError: dynamic module does not define init function (PyInit_vtkCommonCorePython)` – Richard.L Jan 26 '16 at 13:22
  • can you clean the variables (remove vtk from the path) and run my instructions in a command prompt? maybe the error comes from the order in PATH – lib Jan 26 '16 at 13:27
  • OK, but which folder should I enter, there isn't a `Lib` in the folder `User` in my computer as your instructions above. My command prompt is like this : `C:\Users\Dell>` Should I just run the instructions in this path? Sorry that I'm a new fish:( – Richard.L Jan 26 '16 at 13:38
  • yes, C:\Users\lib is my prompt. Actually the path doesn't matter, what you are doing is just setting environment variable in the current command prompt session – lib Jan 26 '16 at 13:42
  • `E:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64>set Path=C:\Program Files\VTK 6.3. 0\bin;%Path% E:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64>set PYTHONPATH=C:\Program Files\VT K 6.3.0\bin\Lib\site-packages E:\WinPython-64bit-3.4.3.5\python-3.4.3.amd64>python -c "import vtk;print vtk.__ file__;print vtk.vtkVersion().GetVTKVersion()" File "", line 1 import vtk;print vtk.__file__;print vtk.vtkVersion().GetVTKVersion() ^ SyntaxError: invalid syntax ` This is what it shows after I did. How annoying:( – Richard.L Jan 26 '16 at 13:56
  • When I run the instructions in `C:\Users\Dell>` it says `python is not an internal or external command`. So I move to the path where WinPython is installed. – Richard.L Jan 26 '16 at 13:59
  • I am not sure that vtk 6 supports python 3 . Have you considered python 2? have a look also at other Canopy/Anaconda https://pyscience.wordpress.com/2014/09/01/anaconda-the-creme-de-la-creme-of-python-distros-3/ – lib Jan 26 '16 at 14:03
  • Well, my tutor asked me to use Python 3 to generate sea surface with `Matplotlib` , `OpenGL` , `VTK` . I have already done with the first two libraries, but blocked by vtk . I have to figure it out ,or I cannot finish the mission that my tutor gave to me.Thank you very much! – Richard.L Jan 26 '16 at 14:15
1

After having the same problem, I gave in and installed the Anaconda python distro. Anaconda has VTK all packaged for download and ready to go. Remember that VTK supports python 2.7.

Edit: Apparently VTK now supports python 3.6

ldgorman
  • 1,553
  • 1
  • 14
  • 39
0

Are you using a 32bit or 64bit version of Python?

VTK seems to be only available for 64bit python installation under Windows. If you can, try installing the 64bit version of Python instead of the 32bit version.

The default download from python.org seems to be the 32bit version of Python.

Stefan
  • 1