Pyrender
Pyrender is a pure Python library (compatible with Python 2.7, 3.4, 3.5, 3.6, though recent Python versions have known issues) for physically-based rendering and visualization. It adheres to the glTF 2.0 specification and provides both an interactive scene viewer and an offscreen renderer capable of GPU-accelerated rendering on headless servers, making it well-suited for machine learning applications. It is lightweight, easy to install, and designed for simplicity of use. The current version is 0.1.45, with development continuing on GitHub.
Warnings
- breaking Pyrender versions on PyPI (including 0.1.45) may be broken on Python 3.12 and 3.13 due to an OpenGL compatibility issue (specifically with OpenGL 3.1.0). A fix exists in the GitHub repository but has not yet been released to PyPI as of late 2025.
- gotcha Offscreen rendering on headless servers often requires specific setup for OpenGL contexts. You might need to install/rebuild Mesa with OSMesa support or ensure EGL 1.5 is available for GPU acceleration.
- gotcha MacOS users may encounter issues with OpenGL contexts when using `pyrender` due to an unreleased `pyglet` fix. A specific fork of `pyglet` is required.
- gotcha The latest PyPI release (0.1.45) is from February 2021. Important bug fixes and improvements that have landed in the GitHub repository since then are not available via `pip install pyrender`.
Install
-
pip install pyrender
Imports
- pyrender
import pyrender
- Mesh
import pyrender mesh = pyrender.Mesh(...)
- Scene
import pyrender scene = pyrender.Scene(...)
- Viewer
import pyrender viewer = pyrender.Viewer(...)
Quickstart
import trimesh
import pyrender
# Load a mesh (e.g., a simple box)
fuze_trimesh = trimesh.creation.icosphere()
mesh = pyrender.Mesh.from_trimesh(fuze_trimesh)
# Create a scene
scene = pyrender.Scene()
scene.add(mesh)
# Add a camera
camera = pyrender.PerspectiveCamera(yfov=0.8, aspectRatio=1.0)
camera_pose = [1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 3.0,
0.0, 0.0, 0.0, 1.0]
scene.add(camera, pose=camera_pose)
# Add some lighting
light = pyrender.DirectionalLight(color=[1.0, 1.0, 1.0], intensity=3.0)
light_pose = [0.0, 0.0, 0.0, 0.0,
-0.5, 0.8, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0]
scene.add(light, pose=light_pose)
# View the scene
pyrender.Viewer(scene, use_raymond_lighting=True)