{"id":10172,"library":"pythreejs","title":"pythreejs","description":"pythreejs provides interactive 3D graphics for the Jupyter Notebook and JupyterLab environments, leveraging the popular Three.js JavaScript library and Jupyter Widgets. It allows Python users to create and manipulate 3D scenes directly within their notebooks. The current version is 2.4.2, and it typically sees a few releases per year, often tracking updates in Three.js or Jupyter widgets.","status":"active","version":"2.4.2","language":"en","source_language":"en","source_url":"https://github.com/jupyter-widgets/pythreejs","tags":["jupyter","3d","graphics","threejs","widgets","visualization"],"install":[{"cmd":"pip install pythreejs","lang":"bash","label":"Install pythreejs"}],"dependencies":[{"reason":"Core dependency for Jupyter widget functionality.","package":"ipywidgets","optional":false}],"imports":[{"symbol":"Scene","correct":"from pythreejs import Scene"},{"symbol":"PerspectiveCamera","correct":"from pythreejs import PerspectiveCamera"},{"symbol":"WebGLRenderer","correct":"from pythreejs import WebGLRenderer"},{"symbol":"Mesh","correct":"from pythreejs import Mesh"},{"symbol":"BoxGeometry","correct":"from pythreejs import BoxGeometry"},{"symbol":"MeshStandardMaterial","correct":"from pythreejs import MeshStandardMaterial"},{"note":"Used for interactive camera control within the renderer.","symbol":"OrbitControls","correct":"from pythreejs import OrbitControls"}],"quickstart":{"code":"from pythreejs import Scene, PerspectiveCamera, WebGLRenderer, Mesh, BoxGeometry, MeshStandardMaterial, OrbitControls\nfrom IPython.display import display\n\n# Create a basic scene with a red cube\nscene = Scene(children=[\n    Mesh(\n        geometry=BoxGeometry(1, 1, 1),\n        material=MeshStandardMaterial(color='red')\n    )\n])\n\n# Set up a camera\ncamera = PerspectiveCamera(position=[3, 3, 3], fov=60, aspect=1.5)\n\n# Create a WebGL renderer and attach the scene and camera\n# Add OrbitControls for interactive camera movement\nrenderer = WebGLRenderer(\n    scene=scene,\n    camera=camera,\n    controls=[OrbitControls(controlling=camera)]\n)\nrenderer.width = 600\nrenderer.height = 400\n\n# Display the interactive 3D renderer in a Jupyter environment\ndisplay(renderer)","lang":"python","description":"This quickstart demonstrates how to create a simple 3D scene with a red cube, set up a camera, and render it using `pythreejs` within a Jupyter Notebook or JupyterLab environment. It also includes `OrbitControls` for interactive camera navigation."},"warnings":[{"fix":"Ensure you are running your pythreejs code within a Jupyter Notebook or JupyterLab. For older Jupyter installations, you might need to manually enable the widgetsnbextension (`jupyter nbextension enable --py widgetsnbextension`).","message":"pythreejs is a Jupyter widget. It will only render correctly within a Jupyter Notebook or JupyterLab environment. Running code outside of these environments (e.g., in a standard Python script or IDE console) will not display the 3D output.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Optimize your scene: use `BufferGeometry` for custom meshes, merge static meshes where possible, reduce polygon count, and be mindful of the number of active lights and post-processing effects.","message":"Performance can degrade rapidly with very complex scenes or a large number of objects. While pythreejs leverages the efficient Three.js library, rendering in a browser context through Jupyter still has limitations.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always consult the pythreejs documentation or examples for your specific version if you encounter unexpected behavior after an update, especially if it relates to object properties or constructor arguments.","message":"pythreejs closely follows the Three.js API. While it aims to abstract most changes, significant updates in underlying Three.js versions can occasionally lead to changes in how certain properties are set or how objects are constructed.","severity":"breaking","affected_versions":"Versions where underlying Three.js updates occurred (e.g., 2.0.0 was a major refactor from 1.x)."}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install pythreejs` to install the package.","cause":"The pythreejs library is not installed in your Python environment.","error":"ModuleNotFoundError: No module named 'pythreejs'"},{"fix":"Try restarting your Jupyter kernel. If the issue persists, ensure `ipywidgets` is installed (`pip install ipywidgets`) and for older Jupyter versions, you might need to manually enable the extension: `jupyter nbextension enable --py widgetsnbextension --sys-prefix` and `jupyter labextension install @jupyter-widgets/jupyterlab-manager` for JupyterLab.","cause":"Jupyter's widget extension is not properly enabled or detected by your Jupyter server, which is necessary for interactive widgets like pythreejs to display.","error":"Widget Javascript not detected. Please confirm the Jupyter server is running the widgetsnbextension."},{"fix":"Verify camera position, target, and `fov`. Ensure there are appropriate light sources (e.g., `DirectionalLight`, `AmbientLight`) in your scene, especially if using materials that react to light. Check object positions relative to the origin and camera.","cause":"Common causes include an incorrectly positioned camera (too far, too close, or pointing away), no light sources in the scene (if using `MeshStandardMaterial`), or objects being outside the camera's view frustum.","error":"The 3D canvas appears blank or shows an empty grey box, even after running the code."}]}