通过 pythreejs 在 JupyterLab 中渲染 cadquery 对象的扩展
The Python package provides a Jupyterlab extension and a JupyterServer extension to view CadQuery, build123d, and OCP objects in JupyterLab
Current version: v5.1.0 (2026-09-11)
The full documentation lives at bernhard-42.github.io/ocp_viewer_docs — the Jupyter CadQuery chapter covers this viewer's specifics; this README gets you installed and running, and links into the rest.
Click on the "launch binder" icon to start Jupyter-CadQuery on binder: (Due to security restrictions, the measurement feature does not work on binder)
Note: JupyterLab 4.6.3 currently does not work with tornado 6.5.9, see here. Ensure to use tornado 6.5.8 for JupyterLab 4.6.3, e.g. pip install "tornado==6.5.8".
CadQuery
Create and activate a virtual conda environment
mamba create -n jcq python=3.12
mamba activate jcqInstall latest cadquery master
mamba install -c conda-forge -c cadquery cadquery=masterInstall Jupyter CadQuery
pip install jupyter-cadquerybuild123d
Create and activate a virtual environment (conda, pyenv-virtualenv, uv, ...)
Install build123d
pip install build123dInstall Jupyter CadQuery
pip install jupyter-cadqueryJupyter CadQuery requires JupyterLab 4 (jupyterlab>=4.6.2,<5) and installs it if it is missing. The JupyterLab extension is prebuilt and ships inside the cad-viewer-widget dependency: no jupyter labextension step, no Node.js.
Known issue: ipykernel 7.x can stall a running notebook (a cell stays at [*] with an idle kernel). Until the ipykernel release that carries the fix, install pip install "ipykernel<7" — details and the workaround in Troubleshooting.
jupyter lab extension list # must list: jupyter_cadquery 5.1.0 OK (the viewer frontend)
jupyter server extension list # must list: jupyter_cadquery 5.1.0 OK (the measurement backend)A line "Extension package jupyter_cadquery took N s to import" is OCP and VTK loading, not an error. On a Mac the very first run can take minutes for the same reason.
cad_width and heightshow is reset_camera=Camera.KEEP now (unless set in ~/.jcq_config differently).ignore_camera_warnings()set_defaults(reset_camera=Camera.RESET)from jupyter_cadquery import * still works. For portable code with other viewers from the ocp viewer ecosystem use from ocp_viewer_core.viewer import *mate_scale does not work any more, use helper_scaleFor all new features and fixes see CHANGELOG
jupyter laband in a notebook:
from build123d import *
from jupyter_cadquery import *
open_viewer("CAD")
show(Box(1, 2, 3))open_viewer puts the viewer into a sidecar panel next to the notebook; without it, show draws into the cell. From here on, everything is in the documentation.
The full documentation lives at bernhard-42.github.io/ocp_viewer_docs — the Jupyter CadQuery chapter covers this viewer's specifics; everything below is a deep link into it.
~/.jcq_configshow* commandsshow commandshow_object commandpush_object and show_objects commandsshow_all commandset_viewer_config commandopen_viewer, close_viewer, export_html, replay, get_pick, …show_clear, save_screenshot, status, …)Camera, Collapse, Render, AnalysisTool, UiTab, Studio*)Standard examples
Animated examples (requires pip install cadquery-massembly matplotlib):
see CHANGELOG.md
Apache-2.0.
暂无开放 Issues,或尚未同步最近议题。