1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
|
.. _building_vtk:
Building VTK
============
Kitware provides Python wheels for VTK at `PyPI VTK
<https://pypi.org/project/vtk/>`_, but there are situations where you
may need to build VTK from source (for example, a new release of Python, EGL
rendering, additional features, etc). As ``pyvista`` does not provide
``vtk``, you will have to either build it manually or install the default
wheel from PyPI.
.. note::
Should you need a prebuilt wheel, a variety of prebuilt wheels can be found at
`pyvista-wheels <https://github.com/pyvista/pyvista-wheels>`_, but you may be
better off building your own. These are not "official" wheels and will soon
be removed in favor of more "official" wheel variants from VTK directly.
Reference the official directions for `Building VTK
<https://gitlab.kitware.com/vtk/vtk/-/blob/master/Documentation/dev/build.md>`_.
The following directions assume you want to build a Python wheel non-standard
situations like EGL.
Building Wheels
~~~~~~~~~~~~~~~
Building VTK from source is fairly straightforward. Using the default build
settings, build a Python wheel of VTK using ``ninja`` using the following
script. This script uses system python3, but you can use any modern Python
version. For some additional useful options, see the `conda-forge recipe
<https://github.com/conda-forge/vtk-feedstock/blob/master/recipe/build.sh>`__.
Most of the ones below are designed to reduce the build time and resulting
wheel size.
.. note::
We have also published some convenient CMake configurations files that you
can adopt from `banesullivan/vtk-cmake <https://github.com/banesullivan/vtk-cmake>`_. These configurations cover the build variants described here
and make the process of reproducibly building VTK wheel variants more
straightforward.
.. code-block:: bash
#!/bin/bash
# Install build dependencies
# Linux/Debian
sudo add-apt-repository -y ppa:deadsnakes/ppa # if on Ubuntu 20.04 or 18.04, building 3.10 for example
sudo apt update
sudo apt install -y ninja-build cmake libgl1-mesa-dev python3-dev git
sudo apt install -y python3.10-dev python3.10-distutils # if using deadsnakes + Python 3.10
# If on 18.04, you'll need a newer cmake. You can follow VTK's instructions @ https://apt.kitware.com
# Linux/CentOS
sudo yum install epel-release
sudo yum install ninja-build cmake mesa-libGL-devel mesa-libGLU-devel
git clone https://gitlab.kitware.com/vtk/vtk.git
mkdir vtk/build
cd vtk/build
git checkout v9.1.0 # optional to select a version, but recommended
export PYBIN=/usr/bin/python3.10 # select your version of choice
cmake -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DVTK_BUILD_TESTING=OFF \
-DVTK_BUILD_DOCUMENTATION=OFF \
-DVTK_BUILD_EXAMPLES=OFF \
-DVTK_DATA_EXCLUDE_FROM_ALL:BOOL=ON \
-DVTK_MODULE_ENABLE_VTK_PythonInterpreter:STRING=NO \
-DVTK_MODULE_ENABLE_VTK_WebCore:STRING=YES \
-DVTK_MODULE_ENABLE_VTK_WebGLExporter:STRING=YES \
-DVTK_MODULE_ENABLE_VTK_WebPython:STRING=YES \
-DVTK_WHEEL_BUILD=ON \
-DVTK_PYTHON_VERSION=3 \
-DVTK_WRAP_PYTHON=ON \
-DVTK_OPENGL_HAS_EGL=False \
-DPython3_EXECUTABLE=$PYBIN ../
ninja
# build wheel in dist
$PYBIN -m pip install wheel
$PYBIN setup.py bdist_wheel
$PYBIN -m pip install dist/vtk-*.whl # optionally install it
.. _gpu_off_screen:
Off-Screen Plotting GPU Support
+++++++++++++++++++++++++++++++
VTK supports rendering with EGL, enabling rapid off-screen rendering
using GPU hardware acceleration without installing a virtual
framebuffer. The default VTK wheels are not built with this feature,
but you can build VTK for off-screen plotting using GPU support by
modifying the above ``cmake`` command with:
.. code-block:: bash
#!/bin/bash
# install build dependencies (Linux/Debian)
apt-get update
apt-get install -y ninja-build cmake libegl1-mesa-dev python3-dev
# build using EGL
git clone https://github.com/Kitware/VTK
mkdir VTK/build
cd VTK/build \
git checkout v9.1.0
cd /VTK/build
cmake -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DVTK_BUILD_TESTING=OFF \
-DVTK_BUILD_DOCUMENTATION=OFF \
-DVTK_BUILD_EXAMPLES=OFF \
-DVTK_MODULE_ENABLE_VTK_PythonInterpreter:STRING=NO \
-DVTK_MODULE_ENABLE_VTK_WebCore:STRING=YES \
-DVTK_MODULE_ENABLE_VTK_WebGLExporter:STRING=YES \
-DVTK_MODULE_ENABLE_VTK_WebPython:STRING=YES \
-DVTK_WHEEL_BUILD=ON \
-DVTK_PYTHON_VERSION=3 \
-DVTK_WRAP_PYTHON=ON \
-DVTK_OPENGL_HAS_EGL:BOOL=ON \
-DVTK_USE_X:BOOL=OFF \
-DVTK_USE_COCOA:BOOL=OFF \
-DVTK_DEFAULT_RENDER_WINDOW_HEADLESS:BOOL=ON \
-DPython3_EXECUTABLE=/usr/bin/python3 ../
ninja
# build the python wheel
python3 -m pip install wheel \
python3 setup.py bdist_wheel \
pip install dist/vtk-*.whl
This disables any plotting using the X server, so be prepared to use
this module only on a headless display where you either intend to save
static images or stream the render window to another computer with a
display (e.g using ``pyvista.set_jupyter_backend('server')`` and
jupyterlab). In other words, this wheel will make VTK unusable outside
of an off-screen environment, so only plan on installing it on a
headless system without an X server.
Building OSMesa
+++++++++++++++
OSMesa provides higher visualization performance on CPU based hosts. Use this
instead of ``xvfb``:
.. code-block:: bash
sudo apt-get install libosmesa6-dev cmake ninja-build
git clone https://github.com/Kitware/VTK.git
cd VTK
git checkout v9.1.0
mkdir build
cd build
PYBIN=/usr/bin/python
cmake -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DVTK_BUILD_TESTING=OFF \
-DVTK_BUILD_DOCUMENTATION=OFF \
-DVTK_BUILD_EXAMPLES=OFF \
-DVTK_DATA_EXCLUDE_FROM_ALL:BOOL=ON \
-DVTK_MODULE_ENABLE_VTK_PythonInterpreter:STRING=NO \
-DVTK_MODULE_ENABLE_VTK_WebCore:STRING=YES \
-DVTK_MODULE_ENABLE_VTK_WebGLExporter:STRING=YES \
-DVTK_MODULE_ENABLE_VTK_WebPython:STRING=YES \
-DVTK_WHEEL_BUILD=ON \
-DVTK_PYTHON_VERSION=3 \
-DVTK_WRAP_PYTHON=ON \
-DVTK_OPENGL_HAS_EGL=False \
-DVTK_OPENGL_HAS_OSMESA=True \
-DVTK_USE_COCOA=FALSE \
-DVTK_USE_X=FALSE \
-DVTK_DEFAULT_RENDER_WINDOW_HEADLESS=True \
-DPython3_EXECUTABLE=$PYBIN ../
ninja
$PYBIN setup.py bdist_wheel
Wheels will be generated in the ``dist`` directory.
Building ManyLinux Wheels
+++++++++++++++++++++++++
The above directions are great for building a local build of VTK, but
these wheels are difficult to share outside your local install given
issues with ABI compatibility due to the version of Linux they were
built on. You can work around this by building your wheels using a
`manylinux <https://github.com/pypa/manylinux>`_ docker image.
To do this, create a ``build_wheels.sh`` with the following contents in the
``git clone`` d ``vtk`` directory, and give it executable permissions
(``chmod +x build_wheels.sh``):
.. code-block:: bash
#!/bin/bash
# builds python wheels on docker container and tests installation
set -e -x
# build based on python version from args
PYTHON_VERSION="$1"
case $PYTHON_VERSION in
3.8)
PYBIN="/opt/python/cp38-cp38/bin/python"
;;
3.9)
PYBIN="/opt/python/cp39-cp39/bin/python"
;;
3.10)
PYBIN="/opt/python/cp310-cp310/bin/python"
;;
3.11)
PYBIN="/opt/python/cp311-cp311/bin/python"
;;
esac
yum install -y ninja-build cmake mesa-libGL-devel mesa-libGLU-devel
rm -rf /io/build
mkdir /io/build -p
cd /io/build
cmake -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DVTK_BUILD_TESTING=OFF \
-DVTK_BUILD_DOCUMENTATION=OFF \
-DVTK_BUILD_EXAMPLES=OFF \
-DVTK_DATA_EXCLUDE_FROM_ALL:BOOL=ON \
-DVTK_MODULE_ENABLE_VTK_PythonInterpreter:STRING=NO \
-DVTK_MODULE_ENABLE_VTK_WebCore:STRING=YES \
-DVTK_MODULE_ENABLE_VTK_WebGLExporter:STRING=YES \
-DVTK_MODULE_ENABLE_VTK_WebPython:STRING=YES \
-DVTK_WHEEL_BUILD=ON \
-DVTK_PYTHON_VERSION=3 \
-DVTK_WRAP_PYTHON=ON \
-DVTK_OPENGL_HAS_EGL=False \
-DPython3_EXECUTABLE=$PYBIN ../
ninja-build
# build wheel in dist
rm -rf dist
$PYBIN -m pip install wheel
$PYBIN setup.py bdist_wheel
# cleanup wheel
rm -rf wheelhouse
auditwheel repair dist/*.whl
This script can then be called with:
.. code-block:: bash
export PYTHON_VERSION=3.10
docker run --cpus 4.5 -e \
--rm -v `pwd`:/io quay.io/pypa/manylinux2014_x86_64 \
/io/build_wheels.sh $PYTHON_VERSION
You should end up with a ``build/wheelhouse/vtk-*.whl``.
.. note::
To build the EGL version of the wheel, follow the directions in the
previous section. Add ``mesa-libEGL-devel`` to the installation
dependencies.
Building Python VTK Wheel on Raspberry Pi (64-bit)
++++++++++++++++++++++++++++++++++++++++++++++++++
While it's possible to build on 32-bit Raspberry Pi (ARMv7), there are
several issues that crop up when building wheels for the 32-bit
version (see `manylinux issue 84
<https://github.com/pypa/manylinux/issues/84>`_). Should you attempt
to build on 32-bit, try building the wheel using `dockcross
<https://github.com/dockcross/dockcross>`_ as you may run into memory
limitations otherwise (especially with only 1 GB RAM).
Building the ``aarch64`` manylinux wheel can be done via docker with
the ``quay.io/pypa/manylinux2014_aarch64`` image. Run the following:
.. code-block:: bash
PYTHON_VERSION=3.8
rm -rf build
docker run -e \
--rm -v `pwd`:/io quay.io/pypa/manylinux2014_aarch64 \
/io/build_wheels.sh $PYTHON_VERSION
Where ``build_wheels.sh`` is:
.. code-block:: bash
#!/bin/bash
# builds python wheels on docker container and tests installation
set -e -x
# build based on python version from args
PYTHON_VERSION="$1"
case $PYTHON_VERSION in
3.8)
PYBIN="/opt/python/cp38-cp38/bin/python"
;;
3.9)
PYBIN="/opt/python/cp39-cp39/bin/python"
;;
3.10)
PYBIN="/opt/python/cp310-cp310/bin/python"
;;
3.11)
PYBIN="/opt/python/cp311-cp311/bin/python"
;;
esac
/bin/bash
yum install epel-release
yum install ninja-build
yum install mesa-libEGL-devel # only needed when building EGL
mkdir /io/build -p
cd /io/build
cmake -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DVTK_BUILD_TESTING=OFF \
-DVTK_BUILD_DOCUMENTATION=OFF \
-DVTK_BUILD_EXAMPLES=OFF \
-DVTK_DATA_EXCLUDE_FROM_ALL:BOOL=ON \
-DVTK_MODULE_ENABLE_VTK_PythonInterpreter:STRING=NO \
-DVTK_MODULE_ENABLE_VTK_WebCore:STRING=YES \
-DVTK_MODULE_ENABLE_VTK_WebGLExporter:STRING=YES \
-DVTK_MODULE_ENABLE_VTK_WebPython:STRING=YES \
-DVTK_WHEEL_BUILD=ON \
-DVTK_PYTHON_VERSION=3 \
-DVTK_WRAP_PYTHON=ON \
-DVTK_OPENGL_HAS_EGL=False \
-DPython3_EXECUTABLE=$PYBIN ../
ninja-build
# build wheel
rm -rf dist
$PYBIN setup.py bdist_wheel
# cleanup wheel
rm -rf wheelhouse
auditwheel repair dist/*.whl
cp wheelhouse/vtk*.whl /io/wheels
Be sure to either enable or disable ``DVTK_OPENGL_HAS_EGL`` depending
on if you want ``EGL`` enabled for your wheel.
|