为 Python 安装 VTK
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15383666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Installing VTK for Python
提问by user1991
I'm trying to install VTK module for python, I am however unsuccesful in doing so. I have downloaded a VTK tar-file, but I'm unable to extract it. I'm capable of extracting other tar-files, so there must be something specific with this file I suppose.
我正在尝试为 python 安装 VTK 模块,但是我这样做没有成功。我已经下载了一个 VTK tar 文件,但我无法解压它。我能够提取其他 tar 文件,所以我想这个文件必须有一些特定的东西。
This is my error:
这是我的错误:
gzip: stdin: invalid compressed data--format violated tar: Child returned status 1 tar: Error is not recoverable: exiting now
gzip: stdin: 无效压缩数据--格式违反 tar: Child 返回状态 1 tar: 错误不可恢复: 现在退出
I hope somebody can help me with this.
我希望有人能帮我解决这个问题。
采纳答案by crayzeewulf
The answer depends on the operating system you are using. This will be a lot easier if you can find a package or installer for your specific operating system and/or distribution.
答案取决于您使用的操作系统。如果您可以找到适用于您的特定操作系统和/或发行版的软件包或安装程序,这将容易得多。
Linux
Linux
If you are using Linux then look for the corresponding package in the distribution's package manager. For example, on Ubuntu Linux you should be able to install it using the following command:
如果您使用的是 Linux,请在发行版的包管理器中查找相应的包。例如,在 Ubuntu Linux 上,您应该能够使用以下命令安装它:
sudo apt-get install python-vtk
Microsoft Windows
微软Windows
If you are using Microsoft Windows, the easiest way would be to install Python(x,y). It comes with VTK support.
如果您使用的是 Microsoft Windows,最简单的方法是安装Python(x,y)。它带有 VTK 支持。
Additionally, Anacondaalso includes VTK package as well as support for virtual environments. It might be a good option for some folks.
此外,Anaconda还包括 VTK 包以及对虚拟环境的支持。对于某些人来说,这可能是一个不错的选择。
Mac OS X
Mac OS X
If you are using Mac OS X, try installing everything via MacPorts.
如果您使用的是 Mac OS X,请尝试通过MacPorts安装所有内容。
As @Nil mentioned in comments below, a standalone python interface to VTK is now provided by VTK developers. You may download it for Windows, Darwin, and Linux from here.
正如@Nil 在下面的评论中提到的,VTK 开发人员现在提供了一个独立的 VTK 的 Python 接口。你可以从这里下载它用于 Windows、Darwin 和 Linux 。
As mentioned by @Nil, VTK used to offer vtkpythonbinaries on their downloadpage. However, they've dropped this since VTK-8.x.x as mentioned here:
正如@Nil 所提到的,VTK 曾经vtkpython在其下载页面上提供二进制文件。然而,他们已经提到,因为VTK-8.xx下跌了这里:
Sorry, about that. We decided to drop the vtkpython binaries for 8. I want to focus our energies on supporting python wheel installs instead. There's no timeline yet for a complete solution but we've made some good progress toward that recently here: https://github.com/jcfr/VTKPythonPackage.
对于那个很抱歉。我们决定放弃 8 的 vtkpython 二进制文件。我想把精力集中在支持 python 轮安装上。目前还没有完整解决方案的时间表,但我们最近在此方面取得了一些不错的进展:https: //github.com/jcfr/VTKPythonPackage。
Thus, the recommended way of installing vtkpythonnow is (see thispage):
因此,vtkpython现在推荐的安装方式是(请参阅此页面):
$ python -m pip install --upgrade pip
$ python -m pip install vtk
回答by user2622509
http://www.lfd.uci.edu/~gohlke/pythonlibs/#vtkTry this! Works for windows !
回答by Kongsea
on Ubuntu, maybe this post will be helpful: http://kazenotaiyo.blogspot.jp/2010/06/installing-vtk-in-ubuntu-and-making.html
在 Ubuntu 上,也许这篇文章会有所帮助:http: //kazenotaiyo.blogspot.jp/2010/06/installing-vtk-in-ubuntu-and-making.html
- The easiest way
- 最简单的方法
The first and easiest is to just install the packages with the Aptitude Package Manager:
第一个也是最简单的方法是使用 Aptitude Package Manager 安装软件包:
sudo apt-get install libvtk5-dev python-vtk
- If you want the newest version
- 如果你想要最新版本
If you want the newest version VTK, you can also build it yourself:
如果你想要最新版本的 VTK,你也可以自己构建:
Make sure CMake is installed:
确保安装了 CMake:
sudo apt-get install cmake
Download the VTK source from the Downloads page.
从下载页面下载 VTK 源代码。
Untar it:
解压它:
tar xvzf vtk-5.6.0.tar.gz
Create an Out-Of-Source build and configure with CMake:
创建一个 Out-Of-Source 构建并使用 CMake 进行配置:
mkdir VTK_BUILD
cd VTK_BUILD
ccmake ../VTK
Make sure you enable python wrapping and set your install prefix to where you want the package to go. The default /usr/local works fine.
确保启用 python 包装并将安装前缀设置为您希望包去的位置。默认的 /usr/local 工作正常。
sudo make -j 8 install
(the -j 8 for make just makes the build process parallel assuming you've got the processors for it)
(假设你有处理器,make 的 -j 8 只是使构建过程并行)
You now have VTK installed. Congrats! if you try to run vtkpython though, you'll get an error:
您现在已经安装了 VTK。恭喜!如果你尝试运行 vtkpython,你会得到一个错误:
vtkpython: error while loading shared libraries: libvtksys.so.5.6: cannot open shared object file: No such file or directory
vtkpython:加载共享库时出错:libvtksys.so.5.6:无法打开共享对象文件:没有这样的文件或目录
To fix this, append these lines to your .bash_profile, .bashrc, or .profile file in your home directory:
要解决此问题,请将这些行附加到主目录中的 .bash_profile、.bashrc 或 .profile 文件中:
# add vtk paths
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib/vtk-5.6"
PYTHONPATH="$PYTHONPATH:/usr/local/lib/vtk-5.6"
You'll need to reset your terminal now.
您现在需要重置终端。
That sets up your library and python paths for the vtkpython executable.
这为 vtkpython 可执行文件设置了您的库和 python 路径。
回答by mrgloom
I have installed vtk without a problem under win7 via pip:
我在win7下通过pip以下方式安装了vtk没有问题:
> pip install vtk
Collecting vtk
Downloading vtk-8.1.0-cp36-cp36m-win_amd64.whl (24.4MB)
100% |████████████████████████████████| 24.4MB 56kB/s
Installing collected packages: vtk
Successfully installed vtk-8.1.0
With Anacond python:
使用 Anacond 蟒蛇:
> python
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

