安装VTK时出现的问题

3

从vtk.org下载最新的VTK版本(7.0.0)的tar.gz文件后,我创建了一个构建文件夹,运行了ccmake,并将标志设置为Python3.5,将PYTHON_WRAPPING标志设置为on,然后运行make命令,接着是make install命令。

>>> import vtk

我遇到了以下错误:

In [1]: import vtk
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/vtk/vtkCommonCore.py in <module>()
      4     # use relative import for installed modules
----> 5     from .vtkCommonCorePython import *
      6 except ImportError:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/vtk/vtkCommonCorePython.so, 2): Library not loaded: libvtkCommonCorePython35D-7.0.1.dylib
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/vtk/vtkCommonCorePython.so
  Reason: image not found

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-b7e11aadda62> in <module>()
----> 1 import vtk

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/vtk/__init__.py in <module>()
     39
     40 # --------------------------------------
---> 41 from .vtkCommonCore import *
     42 from .vtkCommonMath import *
     43 from .vtkCommonMisc import *

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/vtk/vtkCommonCore.py in <module>()
      7     # during build and testing, the modules will be elsewhere,
      8     # e.g. in lib directory or Release/Debug config directories
----> 9     from vtkCommonCorePython import *

ImportError: No module named 'vtkCommonCorePython'

任何想法为什么会发生这种情况?

你已经安装了Python 3.5吗?我猜默认的Python版本是2.7,否则你需要设置更多的变量而不仅仅是PYTHON_WRAPPING。 - jhoepken
2
安装Python 3.5的VTK是一场彻底的噩梦。你纠正其中的一部分,另一部分又会出现问题。我也遇到了完全相同的问题。如果你找到了解决方法,请告诉我们。 - Pouria
1个回答

3

我在VTK的邮件列表上发布了同样的问题,Bernard Giroux的回复起了作用。以下是他的回复(OS X El Capitan):

  1. Run cmake with the following options:

    cmake -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local/VTK-7.0.0 \
    -DVTK_WRAP_PYTHON=ON \
    -DVTK_PYTHON_VERSION=3 \
    -DCMAKE_MACOSX_RPATH=ON \
    -DCMAKE_INSTALL_NAME_DIR=/usr/local/VTK-7.0.0/lib ..
    
  2. Make a symlink in /usr/local VTK -> VTK-7.0.0
  3. In .bash_profile add

    export VTKPATH=/usr/local/VTK
    export PYTHONPATH=$VTKPATH/lib/python3.5/site-packages 
    

    (or whatever the path to python3.5/site-packages is; which python3.5 can be used to get this)

这对我很有帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接