There has been a concerted effort to improve the generation, delivery, and variability of Python wheels for VTK, all published on the VTK GitLab repository’s package registry (thank you, @ben.boeckel!!): https://gitlab.kitware.com/vtk/vtk/-/packages
As of this post, VTK wheels are regularly generated for all OS/arch:
- Release builds on tags (has the official version tag, e.g.:
9.2.6
) - Weekly builds on
master
(has a tag like9.2.20230401.dev0
)
Latest release wheel: https://gitlab.kitware.com/vtk/vtk/-/packages/101
Additional Wheel Variants: OSMesa
On these schedules, different wheel variants can be published, which are differentiated by the package distribution name. Right now, one variant is produced: vtk-osmesa
.
The OSMesa wheel variant has VTK built to leverage offscreen rendering with OSMesa. This wheel is being built for both Linux and Windows at this time and bundles all of the necessary libraries into the wheel. These wheels are intended to be used by downstream projects in headless, CI-like environments or cloud application deployments, preventing the need to install any addition system packages.
Latest release OSMesa wheel: https://gitlab.kitware.com/vtk/vtk/-/packages/102
Making these wheels accessible
You’ll notice on any release page that the install command is currently given as:
pip install vtk --index-url https://gitlab.kitware.com/api/v4/projects/13/packages/pypi/simple
At Kitware, we’ve set up https://wheels.vtk.org to forward to the GitLab package index https://gitlab.kitware.com/api/v4/projects/13/packages/pypi/simple
This means that downstream packages can install from the Kitware-hosted package index by simply adding --extra-index-url https://wheels.vtk.org
to their pip install
command or requirements.txt
pip install --extra-index-url https://wheels.vtk.org vtk
or in requirements.txt
:
--extra-index-url https://wheels.vtk.org
vtk
numpy
# ... other packages
Example installation commands
Install the latest release wheel:
pip install --extra-index-url https://wheels.vtk.org vtk
Install the latest wheel from master
(use --pre
and --no-cache
to grab the most recenet wheel)
pip install --extra-index-url https://wheels.vtk.org vtk --pre --no-cache
Install the OSMesa variant from the latest release
pip install --extra-index-url https://wheels.vtk.org vtk-osmesa
I believe you can also set the environment variable PIP_EXTRA_INDEX_URL
to have this enabled always:
PIP_EXTRA_INDEX_URL='https://wheels.vtk.org'
Note that there are differences in pip’s --extra-index-url
, --index-url
, and --find-links
and you may want to use one over the other for your use case.
Caveats
When using the OSMesa wheel variant, you need to make sure none of the packages in your application require vtk
as pip
thinks vtk
and vtk-osmesa
are different packages (because they are), yet, they’re both under the vtk
namespace and will conflict if installed in the same environment.
One example of where this can be a problem is when wanting the OSMesa wheel with PyVista. PyVista has vtk
in its core requirements, so you either have to tell pip not to install PyVista’s dependencies or uninstall vtk
before installing vtk-osmesa
. This has the potential to be improved once https://github.com/pypa/setuptools/issues/1139 is addressed.
For example:
pip install pyvista
pip uninstall vtk -y
pip install --extra-index-url https://wheels.vtk.org vtk-osmesa
or explicitly install PyVista’s dependencies:
pip install pyvista --no-deps
pip install numpy pillow scooby pooch imageio matplotlib
pip install --extra-index-url https://wheels.vtk.org vtk-osmesa
A better option for custom projects is to not have vtk
be in the core requirements of a package but instead place vtk
and vtk-osmesa
in their own extra_requires
/optional-dependencies
sections:
For setup.py
, this looks like:
setup(
...
extras_require={
'onscreen': ['vtk'],
'offscreen': ['vtk-osmesa'],
}
)
For pyproject.toml
, this looks like:
[project.optional-dependencies]
onscreen = [
'vtk',
]
offscreen = [
'vtk-osmesa',
]
Then install with the extra option:
pip install --extra-index-url https://wheels.vtk.org package[offscreen]