Numpy-stl is a Python library designed to simplify reading, writing, and modifying both binary and ASCII STL (stereolithography) files. Leveraging NumPy, it offers fast and efficient operations for 3D object manipulation. The library is currently at version 3.2.0, with regular updates that include bug fixes, new features, and compatibility enhancements for its core dependencies.
pip install numpy-stlVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a simple cube mesh from vertices and faces and save it to an STL file. It also shows how to load an existing STL file and access some of its properties like the number of triangles and volume. The example includes creating a dummy file if one doesn't exist to ensure the loading part is runnable.
Upgrade to `numpy-stl` version 3.2.0 or newer to ensure full compatibility with NumPy 2.x. If using compiled extensions, recompile them against NumPy 2.x.
Ensure you are using `numpy-stl` version 3.0.0 (or higher) or 2.17.1 (or higher) to benefit from the fixes that prevent floating-point truncation.
If you encounter `ImportError` related to 'stl' or 'mesh', check for other installed packages named 'stl' (e.g., `pip list | grep stl`). Uninstall any conflicting packages (e.g., `pip uninstall stl`) and then reinstall `numpy-stl` if necessary.
Verify that `numpy-stl` is correctly installed (`pip show numpy-stl`). Check for other installed packages named `stl` (e.g., using `pip list | grep stl`) and uninstall them if they are not `numpy-stl`'s module. Reinstall `numpy-stl` if the issue persists: `pip uninstall numpy-stl && pip install numpy-stl`.
Ensure that when creating a new mesh, the data array is initialized with the correct structured dtype from `mesh.Mesh.dtype`. For example: `data = np.zeros(num_faces, dtype=mesh.Mesh.dtype)`.
Double-check the filename and its full or relative path. Ensure the file exists in the expected location. Use `os.path.exists()` to verify the file's presence before attempting to load it.