K3D Jupyter
raw JSON → 2.17.0 verified Fri May 01 auth: no python
K3D is a Jupyter notebook extension for 3D visualization of meshes, points, voxels, and other geometric data using WebGL. Current version is 2.17.0, with occasional releases (last stable in 2023).
pip install k3d Common errors
error ModuleNotFoundError: No module named 'k3d' ↓
cause k3d is not installed.
fix
Run
pip install k3d or conda install -c conda-forge k3d. error ValueError: positions must be a numpy array with dtype float32 ↓
cause k3d >=2.15 enforces float32 dtype for point positions.
fix
Convert your array:
positions = np.array(your_data).astype(np.float32). error Widget failed to display: K3D requires ipywidgets to be installed and enabled. ↓
cause ipywidgets is missing or JupyterLab widget manager is not configured.
fix
Run
pip install ipywidgets and in JupyterLab run jupyter labextension install @jupyter-widgets/jupyterlab-manager. Warnings
gotcha k3d requires Jupyter Notebook or JupyterLab with the lab extension enabled. In JupyterLab, run `jupyter labextension install k3d` if missing. ↓
fix Ensure you have the k3d JupyterLab extension installed: `jupyter labextension install k3d`. For classic notebook, the extension is included.
gotcha The `k3d.plot()` object is a singleton-like pattern; reusing the same plot object without creating a new one can lead to stale renderings. ↓
fix Always create a new plot object for each visualization: `plot = k3d.plot()` before adding objects.
deprecated The `k3d.helix` and `k3d.text` functions were deprecated in 2.14 and removed in 2.17. Use alternative methods for helix and text. ↓
fix For helix, use `k3d.line` with parametric coordinates. For text, consider using matplotlib or an overlay.
breaking As of version 2.15, the `k3d.points` function changed its signature: `positions` expects a numpy array of dtype float32 explicitly. ↓
fix Cast positions to `np.float32` before passing: `positions=np.array(...).astype(np.float32)`.
Imports
- k3d wrong
from k3d import k3dcorrectimport k3d
Quickstart
import k3d
import numpy as np
# Create a plot object
plot = k3d.plot()
# Generate some points
points = np.random.rand(100, 3).astype(np.float32)
colors = np.random.randint(0, 255, (100, 3), dtype=np.uint8)
# Add a point cloud
point_cloud = k3d.points(positions=points, colors=colors, point_size=0.1)
plot += point_cloud
# Display the plot
plot.display()