Polyscope 3D Viewer
Polyscope is a Python library that provides an interactive 3D viewer and user interface for visualizing a variety of 3D data types, including point clouds, surface meshes, volumes, and general purpose quantities. It is built on a C++ core for performance and offers an intuitive GUI. The current version is 2.6.1, and it maintains a frequent release cadence, typically with minor versions released every 1-2 months.
Common errors
-
RuntimeError: Polyscope must be initialized before calling this function.
cause The `ps.init()` function was not called before attempting to register data or interact with the Polyscope backend.fixCall `ps.init()` at the beginning of your script, typically after imports and before any other Polyscope-specific functions are used. -
ImportError: cannot import name 'polyscope_bindings' from 'polyscope'
cause This usually indicates that the underlying C++ library or its Python bindings failed to install or link correctly, often due to platform-specific build issues or missing system dependencies (e.g., C++ compiler, CMake).fixEnsure your environment meets the build requirements if installing from source. For pre-built wheels, try `pip install polyscope --no-cache-dir` to force a fresh install. Check GitHub issues for specific platform solutions if the problem persists. -
No Polyscope window appears, or the window immediately closes after running the script.
cause The `ps.show()` function, which enters the main event loop and displays the GUI, was not called, or the script exited before `ps.show()` could keep the window open.fixEnsure `ps.show()` is called at the very end of your script to keep the GUI open. For advanced use cases or integration in existing loops, consider `ps.frame_tick()` instead of `ps.show()`. -
Polyscope encountered a fatal error: Input data contains NaN or Inf values.
cause One or more NumPy arrays passed to Polyscope (e.g., for vertices, normals, or scalar quantities) contain Not-a-Number (NaN) or infinity (Inf) values.fixInspect and sanitize your input data. Use `numpy.nan_to_num()` or similar methods to replace `NaN`/`Inf` values with zeros or other valid numbers before passing arrays to Polyscope.
Warnings
- breaking Polyscope v2.0.0 introduced significant API changes and a large accumulation of features, which may require code adjustments for users upgrading from pre-2.0.0 versions.
- gotcha Headless rendering (without a display server) using Polyscope, especially on Linux, may require specific setup (e.g., EGL backend) and was experimental before v2.4.0. It may not work out-of-the-box.
- gotcha Input data containing `NaN` (Not-a-Number) or `Inf` (infinity) values can lead to crashes or unexpected visual behavior. Polyscope v2.4.0 introduced checks and warnings for such data.
- gotcha The default camera panning behavior changed in v2.6.0. The turntable center now moves as you pan the camera, which might alter muscle memory for long-time users.
- gotcha Users with high-DPI displays might have experienced blurry text or incorrect UI scaling in versions prior to v2.5.0.
Install
-
pip install polyscope
Imports
- polyscope
import polyscope as ps
Quickstart
import polyscope as ps
import numpy as np
# Initialize polyscope
ps.init()
# Register a point cloud
pts = np.random.rand(100, 3)
ps.register_point_cloud("my_points", pts, color=[0.3, 0.5, 0.8])
# Register a surface mesh
V = np.array([[0,0,0.], [1,0,0.], [0,1,0.], [1,1,0.]])
F = np.array([[0,1,2], [1,3,2]])
ps.register_surface_mesh("my_mesh", V, F, color=[0.8, 0.5, 0.3])
# Show the gui and keep it open
ps.show()