18

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.

This is my error:

gzip: stdin: invalid compressed data--format violated tar: Child returned status 1 tar: Error is not recoverable: exiting now

I hope somebody can help me with this.

user1991
  • 584
  • 1
  • 4
  • 18

5 Answers5

17

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

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:

sudo apt-get install python-vtk

Microsoft Windows

If you are using Microsoft Windows, the easiest way would be to install Python(x,y). It comes with VTK support.

Additionally, Anaconda also includes VTK package as well as support for virtual environments. It might be a good option for some folks.

Mac OS X

If you are using Mac OS X, try installing everything via 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.


As mentioned by @Nil, VTK used to offer vtkpython binaries on their download page. However, they've dropped this since VTK-8.x.x as mentioned here:

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.

Thus, the recommended way of installing vtkpython now is (see this page):

$ python -m pip install --upgrade pip
$ python -m pip install vtk
crayzeewulf
  • 5,840
  • 1
  • 27
  • 30
  • 3
    It seems that vtk now offers a python-vtk installer for Windows, linux and OSX. See their [download page](http://www.vtk.org/VTK/resources/software.html#latestcand) for mroe information. – Nil Mar 05 '14 at 19:45
  • 1
    How about the users of virtual environements? – chiffa Apr 19 '14 at 00:54
5

on Ubuntu, maybe this post will be helpful: 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:

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:

Make sure CMake is installed:

sudo apt-get install cmake

Download the VTK source from the Downloads page.

Untar it:

tar xvzf vtk-5.6.0.tar.gz

Create an Out-Of-Source build and configure with 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.

sudo make -j 8 install

(the -j 8 for make just makes the build process parallel assuming you've got the processors for it)

You now have VTK installed. Congrats! if you try to run vtkpython though, you'll get an error:

vtkpython: error while loading shared libraries: libvtksys.so.5.6: cannot open shared object file: No such file or directory

To fix this, append these lines to your .bash_profile, .bashrc, or .profile file in your home directory:

# 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.

Kongsea
  • 907
  • 12
  • 25
  • 1
    I did as you said, but I'm unable to install it. I get the following error: Package 'python-vtk' has no installation candidate (Using Ubuntu) – fabda01 May 29 '17 at 16:36
  • Any way to _install_ this? I know modifying LD_LIBRARY_PATH and PYTHONPATH work but that's just (essentially) working from the build directory, the contents of which happen to have been copied to /usr/local/lib/vtk-5.6. I want the user to be able to import vtk without requiring them to modify their environment like this, which is considered bad form at the very least. – taranaki Sep 24 '20 at 22:31
4

http://www.lfd.uci.edu/~gohlke/pythonlibs/#vtk Try this! Works for windows !

user2622509
  • 117
  • 1
  • 2
  • 11
  • Yes, although this is cheating. Unfortunatelly, the VTK guys don't publish a package on PyPI, so this is an easy way out of pain. Maybe this is due to licensing issues? – Tomasz Gandor Aug 24 '17 at 10:13
3

I have installed vtk without a problem under win7 via pip:

> 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:

> 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.
mrgloom
  • 20,061
  • 36
  • 171
  • 301
0

MacOS only: See How to Install Mayavi on MacOS

An abridged version of this for MacOS is the following: (but I recommend the full procedure based on above link, but note that it installs Mayavi too)

The following steps seem to work on MacOS:

  1. brew install vtk
  2. pip install vtk

This installs vtk@9.1. You may want to install brew install vtk@8.2 instead.

Tested on: Python: 3.9.13, MacOS: 12.4 Monterey

PS. As mentioned before, this answer may be incomplete (you may need QT too, bu tI am not sure). For a complete one including Mayavi, see My answer here . I suggest following the steps there. I didn't update all content s here because I am not sure which steps are required if you only need VTK (not Mayavi). For example, I don't know whether you need QT or not.

Sohail Si
  • 2,750
  • 2
  • 22
  • 36