meshio is a Python library for reading and writing various unstructured mesh formats, facilitating smooth conversion between them. It supports a wide array of formats including Abaqus, ANSYS msh, Gmsh, STL, VTK, XDMF, and many others. Currently at version 5.3.5, meshio is actively maintained with regular updates and requires Python 3.8 or newer. It can be used both as a command-line tool for conversions and as a Python API for programmatic mesh manipulation.
pip install meshioVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a mesh from points and cells, add associated data (point data, cell data), write it to a VTK file, and then read it back. The `meshio.Mesh` constructor takes points, a list of cell blocks (type and indices), and optional point/cell/field data. The `mesh.write()` method saves the mesh, and `meshio.read()` loads it.
Review and update code that accesses `mesh.cells` or `mesh.cell_data` directly. The structure for `cells` is a list of `(cell_type_string, numpy_array_of_indices)` tuples. Ensure compatibility with meshio's current data structures.
Install `meshio` with all optional dependencies using `pip install meshio[all]` or install specific dependencies (e.g., `h5py`, `netCDF4`, `lxml`) as needed for the desired formats.
Always provide the `cells` argument as a list of `(cell_type_string, numpy_array_of_indices)` tuples. Refer to `meshio` documentation or source for exact cell type strings and expected node ordering for each type (e.g., `meshio._common.num_nodes_per_cell`).
Upgrade `meshio` to version 5.3.5 or newer to ensure full compatibility with NumPy 2.0. If an upgrade is not possible, downgrade NumPy to a compatible version (e.g., NumPy 1.x).
Install `meshio` using pip: `pip install meshio` or `pip install meshio[all]` to include all optional dependencies.
Explicitly specify the file format when reading using the `file_format` argument (e.g., `meshio.read('my_mesh.dat', file_format='tecplot')`). Ensure the file is a valid meshio-supported format and not corrupted. If the format is truly unsupported, consider converting it to a supported format using other tools.Ensure that each item in `cell_data` is an array whose length matches the number of cells in the corresponding `CellBlock`. If reading from a file, this might indicate an issue with the source file's consistency or a limitation in `meshio`'s handling of specific complex Gmsh structures.
When creating the `meshio.Mesh` object, separate different cell types into distinct `CellBlock` entries or consider writing to a more flexible format like VTK or XDMF first, then converting using `meshio-convert` if a multi-cell-type Gmsh output is strictly necessary and supported by a newer Gmsh format version.
Inspect the input mesh file (e.g., an STL file) for corrupted lines or unexpected characters. Ensure the file conforms strictly to the expected format specification. If possible, regenerate the mesh file from its source or try opening it in a dedicated mesh viewer to identify malformations.