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 "<stdin>", line 1, in <module>
File "C:\vtk\Wrapping\Python\vtk\__init__.py", line 41, in <module>
from vtkCommonPython import *
ImportError: No module named vtkCommonPython
I already checked my paths and I have the file 'vtkCommonPython.pyd' in the bin folder.
Can anyone help me with this problem?
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!
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With