Solved ImportError: VTK version conflict with cadquery & stpyvista on Streamlit Cloud

I want to share a solution to a persistent deployment issue that might help other makers working with CAD visualization. When deploying apps using both cadquery and stpyvista to Streamlit Cloud, you might encounter VTK-related import errors.
This happens because cadquery currently depends on an older VTK version (<=9.2.0), while stpyvista requires VTK >=9.4.0. After days of failed deployments and searching through GitHub issues, I finally found the solution in stpyvista’s known issues.

Working solution:
The key is enforcing the correct dependency order in requirements.txt:

streamlit
vtk>=9.4.0  # Explicitly enforce newer VTK first
pyvista
stpyvista
cadquery    # Let this install its dependencies afterward
numpy
panel

And in packages.txt:

libgl1-mesa-glx
libglib2.0-0
libxext6
libsm6
libxrender1
xvfb
procps

Important notes:

  1. The order in requirements.txt is crucial(maybe) - vtk must be declared before cadquery
  2. Some Linux dependencies are required for 3D rendering

I’ve implemented this in my Lego Brick Generator demo that:
:white_check_mark: Generates parametric LEGO-compatible models
:white_check_mark: Exports STEP files
:white_check_mark: Shows 3D preview with stpyvista

You can see my 7(!) failed deployment attempts in the commit history before getting it right :sweat_smile:

Hope this helps others struggling with CAD/3D deployments!

1 Like

I’ll link this post in the Readme!