{"id":10092,"library":"pyevtk","title":"Python EVTK Library","description":"pyevtk is a Python library for exporting numerical data (like structured grids, unstructured grids, and points) into binary VTK (Visualization Toolkit) files, enabling visualization in tools like ParaView or VisIt. As of version 1.6.0, it supports various data types and has an active, albeit slow, release cadence.","status":"active","version":"1.6.0","language":"en","source_language":"en","source_url":"https://github.com/pyscience-projects/pyevtk","tags":["VTK","visualization","data export","scientific computing","numpy"],"install":[{"cmd":"pip install pyevtk","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The `evtk` package is an alias for `pyevtk` for backward compatibility but is deprecated and will issue a warning. Always use `pyevtk`.","wrong":"from evtk.hl import gridToVTK","symbol":"gridToVTK","correct":"from pyevtk.hl import gridToVTK"},{"symbol":"pointsToVTK","correct":"from pyevtk.hl import pointsToVTK"},{"symbol":"imageToVTK","correct":"from pyevtk.hl import imageToVTK"}],"quickstart":{"code":"import numpy as np\nfrom pyevtk.hl import gridToVTK\n\n# Define grid dimensions\nnx, ny, nz = 64, 64, 64\n\n# Coordinates\nx = np.arange(0, nx, 1, dtype='float64')\ny = np.arange(0, ny, 1, dtype='float64')\nz = np.arange(0, nz, 1, dtype='float64')\n\n# Cell data (e.g., temperature)\ntemp = np.random.rand(nx - 1, ny - 1, nz - 1)\n\n# Point data (e.g., pressure)\npress = np.random.rand(nx, ny, nz)\n\n# Export to VTK file\ngridToVTK(\n    \"output_grid\",\n    x, y, z,\n    cellData={'temperature': temp},\n    pointData={'pressure': press}\n)\n\nprint(\"VTK file 'output_grid.vts' generated successfully.\")","lang":"python","description":"This quickstart demonstrates how to export a structured grid with both cell-centered and point-centered data to a VTK Structured Grid (.vts) file using `gridToVTK`."},"warnings":[{"fix":"Always use `from pyevtk.hl import ...` for all imports, e.g., `from pyevtk.hl import gridToVTK`.","message":"Using `from evtk.hl import ...` is deprecated. The `evtk` package is an alias for `pyevtk` for backward compatibility but will issue a `DeprecationWarning` and may be removed in future versions.","severity":"deprecated","affected_versions":">=1.1.2"},{"fix":"Ensure all array inputs are `numpy.ndarray` objects. Convert them using `numpy.asarray()` if necessary.","message":"All input data arrays (e.g., `data`, `x`, `y`, `z` coordinates) must be NumPy arrays. Passing standard Python lists or other array-like objects will result in `TypeError` or unexpected behavior.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be mindful of whether your data is node-centered or cell-centered. If your data is node-centered on an `(Nx, Ny, Nz)` grid, the data array passed to `gridToVTK` for cell data should typically have dimensions `(Nx-1, Ny-1, Nz-1)` to align correctly. Alternatively, explicitly define point data if appropriate.","message":"VTK files generated by `pyevtk` often assume cell-centered data for structured grids. Misinterpreting this can lead to data being shifted by half a cell when visualized in tools like ParaView if your data is node-centered.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Change all imports from `evtk` to `pyevtk`, e.g., `from pyevtk.hl import gridToVTK`.","cause":"Attempting to import from the deprecated `evtk` package, which might not be installed or available as an alias in the current environment/version.","error":"ModuleNotFoundError: No module named 'evtk'"},{"fix":"Convert the input data to a NumPy array before passing it to `pyevtk` functions, e.g., `import numpy as np; data = np.asarray(my_list)`.","cause":"Input data (e.g., field values, coordinate arrays) was provided as a Python list or non-NumPy array.","error":"TypeError: Expected a numpy array for 'data' but got <class 'list'>"},{"fix":"Carefully check the expected dimensions for the specific VTK export function being used. For cell data on an `(nx, ny, nz)` grid, the data array should typically have shape `(nx-1, ny-1, nz-1)`. For point data, it should be `(nx, ny, nz)`.","cause":"The shape of the data array (e.g., `cellData` or `pointData`) does not correspond to the dimensions of the grid (e.g., `(nx, ny, nz)` for structured grids).","error":"ValueError: Data dimensions do not match grid dimensions."}]}