TetGen Python Interface

raw JSON →
0.8.3 verified Fri May 01 auth: no python

Python wrapper for the TetGen tetrahedral mesh generator, providing high-quality tetrahedral meshing of 3D polyhedral domains. Currently at version 0.8.3, with releases approximately every 6-12 months. Part of the PyVista ecosystem.

pip install tetgen
error ModuleNotFoundError: No module named 'tetgen'
cause Package not installed or misspelled.
fix
Run 'pip install tetgen'. Ensure import uses lowercase 'tetgen'.
error ImportError: cannot import name 'TetGen' from 'tetgen'
cause Incorrect import statement; 'TetGen' is the class.
fix
Use 'from tetgen import TetGen'.
error RuntimeError: TetGen returned 0 tetrahedra
cause Input surface mesh is not closed, is non-manifold, or has self-intersections.
fix
Check mesh closure with 'mesh.is_all_manifold' and 'mesh.is_closed'. Repair as needed.
breaking In v0.8.0, the Cython backend was replaced with nanobind. This may cause subtle differences in numerical results and break custom builds.
fix Upgrade and re-test tetrahedralizations. Avoid relying on Cython-specific behavior.
deprecated Method compute_cell_quality was renamed to cell_quality in v0.6.7.
fix Use tet.cell_quality instead of tet.compute_cell_quality.
breaking Version 0.8.3 requires Python >=3.10. No wheels for older Python versions.
fix Use Python 3.10+.
gotcha TetGen expects a closed, manifold surface mesh. Non-manifold or open meshes will fail silently or produce incorrect results.
fix Clean the input mesh (e.g., with PyVista's clean, merge, or manifold checks) before passing to TetGen.

Load a surface mesh, create a TetGen instance, tetrahedralize, and access the output mesh.

import pyvista as pv
from tetgen import TetGen

# Load or create a surface mesh (must be a closed, manifold PolyData)
mesh = pv.Sphere()

# Initialize TetGen with the surface
tet = TetGen(mesh)

# Generate tetrahedral mesh (apply attributes/flags as needed)
tet.tetrahedralize()

# Access the resulting tetrahedral mesh
tet_grid = tet.grid
print(tet_grid)