Registry / data / gmsh
library4.15.2pypypi✓ verified 84d ago

Gmsh is an open-source three-dimensional finite element mesh generator with built-in pre- and post-processing facilities. It is designed to be fast, light, and user-friendly, supporting parametric input and flexible visualization capabilities. The library is actively maintained, with version 4.15.2 released on March 24, 2026, and regular updates.

pip install gmsh
INSTALL
IMPORT
SIG · GMSH
G
gmsh
datapythonv4.15.2
Install
2.7s avg
Import
Disk
17MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.15.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
build_error
glibc
py 3.103.940 runs
installs and imports cleanly · install 2.7s · import 0.000s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

gmsh
import gmsh

This quickstart generates a simple 2D square mesh using the built-in CAD kernel, saves it to a `.msh` file, and properly initializes and finalizes the Gmsh API. It demonstrates the fundamental steps of geometry definition, synchronization, mesh generation, and output.

import gmsh import sys gmsh.initialize(sys.argv) try: gmsh.model.add("square_mesh") # Define a characteristic length (mesh size) lc = 0.1 # Create points p1 = gmsh.model.geo.addPoint(0, 0, 0, lc) p2 = gmsh.model.geo.addPoint(1, 0, 0, lc) p3 = gmsh.model.geo.addPoint(1, 1, 0, lc) p4 = gmsh.model.geo.addPoint(0, 1, 0, lc) # Create lines l1 = gmsh.model.geo.addLine(p1, p2) l2 = gmsh.model.geo.addLine(p2, p3) l3 = gmsh.model.geo.addLine(p3, p4) l4 = gmsh.model.geo.addLine(p4, p1) # Create a curve loop and plane surface curve_loop = gmsh.model.geo.addCurveLoop([l1, l2, l3, l4]) plane_surface = gmsh.model.geo.addPlaneSurface([curve_loop]) # Synchronize the CAD kernel with the Gmsh model gmsh.model.geo.synchronize() # Add a physical group for the surface (optional, but good practice) gmsh.model.addPhysicalGroup(2, [plane_surface], tag=1) gmsh.model.setPhysicalName(2, 1, "MySurface") # Generate a 2D mesh gmsh.model.mesh.generate(2) # Write the mesh to a .msh file gmsh.write("square.msh") # Optional: uncomment to launch the Gmsh GUI to visualize the mesh # if '-nopopup' not in sys.argv: # gmsh.fltk.run() except Exception as e: print(f"An error occurred: {e}") finally: gmsh.finalize()
gmsh --version
Debug
Known issues
gotchaAlways call `gmsh.initialize()` at the beginning of your script and `gmsh.finalize()` at the end. Failing to do so can lead to memory leaks, unexpected behavior, or resource contention if Gmsh is used in subsequent processes.
fix
Ensure `gmsh.initialize()` is called before any other Gmsh API function and `gmsh.finalize()` is called at script termination, ideally in a `try...finally` block.
affects: All versions
gotchaAfter creating or modifying geometry entities (points, lines, surfaces, volumes), you must call `gmsh.model.geo.synchronize()` (for the built-in kernel) or `gmsh.model.occ.synchronize()` (for the OpenCASCADE kernel) to update the Gmsh internal model before meshing or performing other model operations. Forgetting this step can result in an empty or outdated mesh.
fix
Insert `gmsh.model.geo.synchronize()` or `gmsh.model.occ.synchronize()` after a series of geometry creation commands and before mesh generation.
affects: All versions
breakingBeginning with Gmsh version 4.5.0, API errors now consistently throw Python exceptions by default (instead of returning an integer error code). This improves error handling but may break scripts that relied on checking numerical return codes.
fix
Update scripts to use standard Python `try...except` blocks to catch `Exception` for Gmsh API errors, or disable default exception throwing by setting `gmsh.option.setNumber('General.AbortOnError', 0)` if preferred (though not recommended).
affects: >=4.5.0
deprecatedGmsh primarily generates triangular or tetrahedral meshes and then uses recombination algorithms to form quadrilaterals or hexahedra. Sometimes, this can result in meshes with mixed element types (e.g., quads and triangles), which may not be supported by all downstream finite element solvers.
fix
Explicitly set meshing options like `gmsh.option.setNumber('Mesh.RecombinationAlgorithm', 2)` and `gmsh.option.setNumber('Mesh.RecombineAll', 1)` to encourage quad/hexa generation, but be aware that mixed elements might still occur. Inspect your mesh output carefully and adjust options or geometry if necessary.
affects: All versions
Errors
Common errors & fixes
AttributeError: dlsym(RTLD_DEFAULT, gmshInitialize)
This error typically occurs when the Gmsh Python module cannot find or correctly load the underlying Gmsh shared library. This can happen due to incompatible Python environments, incorrect installation paths, or conflicts with other libraries, especially in bundled applications like FreeCAD.
fix
Ensure `gmsh` is installed in the correct Python environment. If using a specific application's Python interpreter, verify its compatibility. Sometimes, reinstalling `gmsh` or using `gmsh.initialize(readConfigFiles=False)` can resolve the issue.
Exception "Could not get last error" raised by gmsh.initialize()
This cryptic error during initialization often indicates corrupted Gmsh configuration files or issues with file permissions in the user's Gmsh configuration directory. It prevents the API from starting correctly.
fix
Try calling `gmsh.initialize(readConfigFiles=False)`. If this works, it confirms a configuration file issue. You might need to locate and delete or reset Gmsh configuration files (e.g., `gmsh.opt` or `gmsh.rc`) in your user's application data directory, or specify a clean working directory.
Error: Unable to recover the edge XXX on curve YYY (on surface ZZZ)
This error points to a problem with the geometric definition, specifically when meshing curves that are not well-defined or form self-intersecting loops. For instance, defining a closed loop with a single spline instead of multiple distinct lines can lead to ambiguity.
fix
Review the geometry definition. Ensure that closed loops are formed by a sequence of distinct lines/curves. Break down complex splines into simpler segments if necessary, and ensure all entities are correctly oriented and connected.
OSError: exception: access violation writing 0x00000000XXXXXXXX
An 'access violation' error, particularly when calling `gmsh.model.mesh.generate()`, often indicates a low-level memory access problem within the Gmsh library. This can be triggered by complex geometries, specific meshing algorithms, or when generating higher-order elements, especially on Windows.
fix
Simplify the geometry or reduce meshing complexity (e.g., try generating a 1st-order mesh first). Update Gmsh to the latest version, as these can sometimes be platform-specific bugs. Ensure sufficient memory is available for the meshing operation.
Upgrade
Version history
4.15.2latest on PyPI · released Mar 24, 2026
Audit
Dependencies
numpyoptionalCommonly used for numerical operations and array manipulation in scripts interacting with mesh data.
meshiooptionalA versatile mesh I/O library often used to read/write various mesh formats, including .msh files generated by Gmsh, for compatibility with other FEM solvers.
dolfinxoptionalA finite element solver often integrated with Gmsh for mesh generation and subsequent simulations.
Agent activity
43 hits · last 30 days
node
40
OpenAI (training)
1
Resources
gmsh — pip install gmsh · libregistry