Welcome to VTKPythonPackage’s documentation!

This project provides a setup.py script to build VTK Python wheels.

VTK is an open-source, cross-platform system that provides developers with an extensive suite of software tools for 3D computer graphics, image processing, and visualization.

The Python packages are built daily. To install the VTK Python package:

$ python -m pip install --upgrade pip
$ python -m pip install vtk

For more information on VTK’s Python wrapping, see VTK Python Wrapping FAQ. There are also many downloadable examples.

Automated wheels building with scripts

Steps required to build wheels on Linux, MacOSX and Windows have been automated. The following sections outline how to use the associated scripts.

Linux

On any linux distribution with docker and bash installed, running the script dockcross-manylinux-build-wheels.sh will create 64-bit wheels for both python 2.x and python 3.x in the dist directory.

For example:

$ git clone https://github.com/KitwareMedical/VTKPythonPackage.git
[...]

$ ./scripts/dockcross-manylinux-build-wheels.sh
[...]

$ ls -1 dist/
vtk-8.0.0.dev20170714-cp27-cp27m-manylinux1_x86_64.whl
vtk-8.0.0.dev20170714-cp27-cp27mu-manylinux1_x86_64.whl
vtk-8.0.0.dev20170714-cp34-cp34m-manylinux1_x86_64.whl
vtk-8.0.0.dev20170714-cp35-cp35m-manylinux1_x86_64.whl
vtk-8.0.0.dev20170714-cp36-cp36m-manylinux1_x86_64.whl

MacOSX

Download and install python from https://www.python.org/downloads/mac-osx/. Run macos_build_wheels.py to create wheels for python 3.5, 3.6 and 3.7 in the dist directory.

For example:

$ git clone https://github.com/KitwareMedical/VTKPythonPackage.git

$ python ./scripts/macos_build_wheels.py.

$ ls -1 dist/
vtk-8.0.0.dev20170714-cp34-cp34m-macosx_10_9_x86_64.whl
vtk-8.0.0.dev20170714-cp35-cp35m-macosx_10_9_x86_64.whl
vtk-8.0.0.dev20170714-cp36-cp36m-macosx_10_9_x86_64.whl

Windows

First, install Microsoft Visual C++ Compiler for Python 2.7, Visual Studio 2015, Git, and CMake, which should be added to the system PATH environmental variable.

Open a PowerShell terminal as Administrator, and install Python:

PS C:\> Set-ExecutionPolicy Unrestricted
PS C:\> iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/scikit-build/scikit-ci-addons/master/windows/install-python.ps1'))

In a PowerShell prompt:

PS C:\Windows> cd C:\
PS C:\> git clone https://github.com/KitwareMedical/VTKPythonPackage.git VPP
PS C:\> cd VPP
PS C:\VPP> C:\Python27-x64\python.exe .\scripts\windows_build_wheels.py
[...]

PS C:\VPP> ls dist
    Directory: C:\VPP\dist


    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----        7/16/2017   5:21 PM       ???????? vtk-8.0.0.dev20170714-cp27-cp27m-win_amd64.whl
    -a----        7/16/2017  11:14 PM       ???????? vtk-8.0.0.dev20170714-cp35-cp35m-win_amd64.whl
    -a----        7/16/2017   2:08 AM       ???????? vtk-8.0.0.dev20170714-cp36-cp36m-win_amd64.whl

We need to work in a short directory to avoid path length limitations on Windows, so the repository is cloned into C:VPP. Also, it is very important to disable antivirus checking on the C:VPP directory. Otherwise, the build system conflicts with the antivirus when many files are created and deleted quickly, which can result in Access Denied errors. Windows 10 ships with an antivirus application, Windows Defender, that is enabled by default.

sdist

To create source distributions, sdist’s, that will be used by pip to compile a wheel for installation if a binary wheel is not available for the current Python version or platform:

$ python setup.py sdist --formats=gztar,zip
[...]

$ ls -1 dist/
vtk-8.0.0.dev20170714.tar.gz
vtk-8.0.0.dev20170714.zip

Prerequisites

Building wheels requires:

  • CMake
  • Git
  • C++ Compiler - Platform specific requirements are summarized in scikit-build documentation.
  • Python

Detailed build instructions

Building VTK Python wheels

Build the VTK Python wheel with the following command:

mkvirtualenv build-vtk
pip install -r requirements-dev.txt
python setup.py bdist_wheel

Efficiently building wheels for different version of python

If on a given platform you would like to build wheels for different version of python, you can download and build the VTK components independent from python first and reuse them when building each wheel.

Here are the steps:

  • Build VTKPythonPackage with VTKPythonPackage_BUILD_PYTHON set to OFF.

  • Build “flavor” of package using:

    python setup.py bdist_wheel -- \
      -DVTK_SOURCE_DIR:PATH=/path/to/VTKPythonPackage-core-build/VTK-source
    

Miscellaneous

Initially written by Jean-Christophe Fillion-Robin and Matt McCormick from Kitware Inc during the SciPy 2017 sprints with inputs from Matthew Brett (Birmingham University College of Life and Environmental Sciences), Dave DeMarle (Kitware Inc), David Gobbi (University of Calgary) and Prabhu Ramachandran (IIT Bombay).

It is covered by the OSI-approved BSD 3-clause License:

https://github.com/jcfr/VTKPythonPackage/blob/master/LICENSE

For more information about VTK, visit http://vtk.org

Indices and tables