mayavi 4.8.3 installation segfault
Recently I've been trying to use mayavi in a project that's using uv to manage the packages:
$ uv add mayavi
Resolved 31 packages in 5.14s
× Failed to build `mayavi==4.8.3`
├─▶ The build backend returned an error
╰─▶ Call to `setuptools.build_meta:__legacy__.build_wheel` failed (signal: 11 (SIGSEGV) (core dumped))
[stdout]
running bdist_wheel
running build
running build_py
Building tvtk_classes.zip
As you can see this command has failed, here's some relevant output:
[stderr]
/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/dist.py:759:
SetuptoolsDeprecationWarning: License classifiers are deprecated.
!!
********************************************************************************
Please consider removing the following classifiers in favor of a SPDX license expression:
License :: OSI Approved :: BSD License
See https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license for details.
********************************************************************************
!!
self._finalize_license_expression()
Bad to call vtkUniformHyperTreeGrid::GetXCoordinates
Bad to call vtkUniformHyperTreeGrid::GetYCoordinates
Bad to call vtkUniformHyperTreeGrid::GetZCoordinates
Fatal Python error: Segmentation fault
Current thread 0x000075237e4f1080 (most recent call first):
File "/home/janis/.cache/uv/sdists-v9/pypi/mayavi/4.8.3/dDnd2U-_4G8AggXDGd8tV/src/tvtk/vtk_parser.py", line 725 in
_find_get_set_methods
File "/home/janis/.cache/uv/sdists-v9/pypi/mayavi/4.8.3/dDnd2U-_4G8AggXDGd8tV/src/tvtk/vtk_parser.py", line 493 in
_organize_methods
File "/home/janis/.cache/uv/sdists-v9/pypi/mayavi/4.8.3/dDnd2U-_4G8AggXDGd8tV/src/tvtk/vtk_parser.py", line 159 in parse
File "/home/janis/.cache/uv/sdists-v9/pypi/mayavi/4.8.3/dDnd2U-_4G8AggXDGd8tV/src/tvtk/wrapper_gen.py", line 338 in
_gen_methods
File "/home/janis/.cache/uv/sdists-v9/pypi/mayavi/4.8.3/dDnd2U-_4G8AggXDGd8tV/src/tvtk/wrapper_gen.py", line 239 in
generate_code
File "/home/janis/.cache/uv/sdists-v9/pypi/mayavi/4.8.3/dDnd2U-_4G8AggXDGd8tV/src/tvtk/code_gen.py", line 241 in
_write_wrapper_class
File "/home/janis/.cache/uv/sdists-v9/pypi/mayavi/4.8.3/dDnd2U-_4G8AggXDGd8tV/src/tvtk/code_gen.py", line 148 in
generate_code
File "/home/janis/.cache/uv/sdists-v9/pypi/mayavi/4.8.3/dDnd2U-_4G8AggXDGd8tV/src/tvtk/_setup.py", line 58 in
gen_tvtk_classes_zip
File "<string>", line 247 in build_tvtk_classes_zip
File "<string>", line 254 in run
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1021
in run_command
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/dist.py", line 1102 in
run_command
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 357
in run_command
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/_distutils/command/build.py",
line 135 in run
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1021
in run_command
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/dist.py", line 1102 in
run_command
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/_distutils/cmd.py", line 357
in run_command
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/command/bdist_wheel.py", line
370 in run
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1021
in run_command
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/dist.py", line 1102 in
run_command
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/_distutils/dist.py", line 1002
in run_commands
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 202
in run_commands
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/_distutils/core.py", line 186
in setup
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/__init__.py", line 115 in setup
File "<string>", line 322 in <module>
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/build_meta.py", line 317 in
run_setup
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/build_meta.py", line 512 in
run_setup
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/build_meta.py", line 404 in
_build_with_temp_dir
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/build_meta.py", line 423 in
_build
File "/home/janis/.cache/uv/builds-v0/.tmpsBzI14/lib/python3.12/site-packages/setuptools/build_meta.py", line 432 in
build_wheel
File "<string>", line 11 in <module>
Looking through github issues seemed to suggest the problem was an interaction with vtk==9.5 so I attempted to instal an older version of vtk first:
$ uv pip install "vtk < 9.5"
Resolved 12 packages in 487ms
Prepared 1 package in 36.83s
Installed 10 packages in 17ms
+ contourpy==1.3.2
+ cycler==0.12.1
+ fonttools==4.58.5
+ kiwisolver==1.4.8
+ matplotlib==3.10.3
+ packaging==25.0
+ pillow==11.3.0
+ python-dateutil==2.9.0.post0
+ six==1.17.0
+ vtk==9.4.2
But then attempting to install mayavi with the same command as above was still failing with a segfault. Next attempt:
$ uv pip install mayavi --no-cache-dir --verbose --no-build-isolation
Failed with this:
DEBUG ModuleNotFoundError: No module named 'setuptools'
DEBUG Released lock at `/tmp/.tmpkRLkjZ/sdists-v9/pypi/mayavi/4.8.3/.lock`
× Failed to build `mayavi==4.8.3`
├─▶ The build backend returned an error
╰─▶ Call to `setuptools.build_meta:__legacy__.build_wheel` failed (exit status: 1)
[stderr]
Traceback (most recent call last):
File "<string>", line 8, in <module>
ModuleNotFoundError: No module named 'setuptools'
hint: This usually indicates a problem with the package or the build environment.
Apparently this now runs into some setuptools related breakage as a result of using the --no-build-isolation as the setuptools at the global level has the bug. Apaprently this issue is fairly common: https://github.com/pypa/setuptools/issues/4519
$ uv pip install mayavi --no-cache-dir --verbose
This now fails with the same segfault as before.
specifying the uv build system in pyproject.toml:
[build-system]
requires = ["uv_build>=0.7.19,<0.8.0"]
build-backend = "uv_build"
Now avoids the issue with setuptools but still fails with the segfault.
Attempting to pin the version of VTK first:
$ uv add vtk==9.4.2
Still segfaults on the attempt to install mayavi when using uv add mayavi.
What makes this situation difficult is that multiple bugs are happening all at once which obscures the situation.
Firstly mayavi==4.8.3 isn't compatible with vtk==9.5.0 but yet mayavi doesn't restrict to vtk<9.5 in its install file. This then leads to a standard invocation of uv add mayavi failing with a segfault.
Then when you attempt to pin a version like this:
$ uv add mayavi==4.7.3
× Failed to build `mayavi==4.7.3`
├─▶ The build backend returned an error
╰─▶ Call to `setuptools.build_meta:__legacy__.prepare_metadata_for_build_wheel` failed (exit status: 1)
[stdout]
********************************************************************************
Numpy is required to build Mayavi correctly, please install it first.
********************************************************************************
[stderr]
<string>:126: SyntaxWarning: invalid escape sequence '\.'
<string>:127: SyntaxWarning: invalid escape sequence '\.'
<string>:151: SyntaxWarning: invalid escape sequence '\.'
<string>:152: SyntaxWarning: invalid escape sequence '\.'
Traceback (most recent call last):
File "<string>", line 14, in <module>
File
"/home/janis/experimental-code/.venv/lib/python3.12/site-packages/setuptools/build_meta.py",
line 374, in prepare_metadata_for_build_wheel
self.run_setup()
File
"/home/janis/experimental-code/.venv/lib/python3.12/site-packages/setuptools/build_meta.py",
line 512, in run_setup
super().run_setup(setup_script=setup_script)
File
"/home/janis/experimental-code/.venv/lib/python3.12/site-packages/setuptools/build_meta.py",
line 317, in run_setup
exec(code, locals())
File "<string>", line 406, in <module>
RuntimeError:
Numpy is required to build Mayavi correctly, please install it first.
hint: This usually indicates a problem with the package or the build environment.
help: If you want to add the package regardless of the failed resolution, provide the `--frozen` flag to skip locking and
syncing.
You find that you have to build without the standard build isolation that uv provides. But if you don't specify numpy as a build dependency the build fails anyway even if in [project] dependencies you had specified numpy as a dependency of the main project. This is especially insidious because you might thing "WTF I specified numpy as a dependency already". But what you have to do is add this dependency in requires-dist for mayavi.
This is what I ened up with in pyproject.toml:
[project]
name = "experimental-code"
version = "0.1.0"
description = "Experimental code"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"numpy>=2.3.1",
"rasterio>=1.4.3",
"vtk==9.4.2",
"mayavi==4.8.3",
]
[tool.uv]
no-build-isolation-package = ["mayavi"]
[[tool.uv.dependency-metadata]]
name = "mayavi"
version = "4.8.3"
requires-dist = ["numpy"]
Then following up with uv sync to install.
I just couldn't get uv add mayavi to work without pinning to an old version of vtk. Honestly I think mayavi should restrict VTK to <9.5 in their setup so this bug doesn't burn people since VTK==9.5.0 seems to segfault on installation of mayavi.
At this point I've thrown away multiple orders of magnitude more time fighting python packaging bugs than the small thing I wanted to try with mayavi. Because I have things I need to get done I was very close to just giving up and moving on to some other library that would install more easily. This is a pity because mayavi looks like a good package, but this level of difficulty in installing makes it infeasible to use for the vast majority of people. I figure that if someone who is a python packaging veteran has to spend multiple hours trying to debug installation the average person is just going to give up.
EDIT: Unfortunately this isn't the end of it, see this article for part 2, after you get past the install segfault problems there's a bunch of other bugs.
This post is part 1 of the "mayavi-installation" series: