Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
144 views
in Technique[技术] by (71.8m points)

python - ImportError: No module named vtkCommonPython

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:vtkWrappingPythonvtk\__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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...