Pyrr
raw JSON → 0.10.3 verified Fri May 01 auth: no python
Pyrr provides 3D mathematical functions (matrices, quaternions, vectors, eulers) using NumPy arrays. Current version: 0.10.3. Infrequent releases, last stable in 2022.
pip install pyrr Common errors
error ImportError: cannot import name 'matrix44' from 'pyrr' ↓
cause After 0.9.0, some submodules like 'pyrr.matrix44' are still present but functions have been renamed. However, the import itself should work if the module exists. This error may occur if the package is not installed correctly or if there's a naming confusion.
fix
Run
pip install --upgrade pyrr. Then use from pyrr.matrix44 import create_from_translation. error ValueError: The truth value of an array with more than one element is ambiguous. ↓
cause Using a Pyrr object (e.g., Vector3) in a boolean context (if vec: ...). Pyrr objects inherit NumPy array behavior and cannot be used as booleans directly.
fix
Use
if vec.any(): or if vec.all(): depending on intent. error AttributeError: 'Matrix44' object has no attribute 'create_look_at' ↓
cause Using old API. `create_look_at` is a module-level function, not a method on Matrix44. Also, it was renamed in 0.9.0.
fix
Use
from pyrr.matrix44 import create_look_at and call create_look_at(eye, target, up). Warnings
breaking In version 0.8.0, the parameter order for `euler.create_from_euler` changed from (pitch, roll, yaw) to (roll, pitch, yaw). Code using the old order will produce incorrect rotations. ↓
fix Update calls: `euler.create_from_euler(roll, pitch, yaw, ...)` instead of `(pitch, roll, yaw, ...)`.
breaking In version 0.9.0, many matrix functions with '_matrix' in the name were deprecated. For example, `matrix44.create_look_at_matrix` is deprecated in favor of `matrix44.create_look_at`. ↓
fix Use the new function names without '_matrix'. Check the deprecation warnings in your code.
gotcha Pyrr internally uses NumPy arrays. Directly mutating the underlying array can cause unexpected behavior. Always use the provided methods or create new objects. ↓
fix Avoid modifying `obj.flat` or `.data`; use obj.copy() or constructors.
Imports
- Matrix44
from pyrr import Matrix44 - Quaternion
from pyrr import Quaternion - Vector3
from pyrr import Vector3 - matrix44 wrong
from pyrr import matrix44correctfrom pyrr.matrix44 import create_from_translation - euler
from pyrr import euler
Quickstart
import numpy as np
from pyrr import Matrix44, Vector3, Quaternion
# Create a translation matrix
trans = Matrix44.from_translation([1, 2, 3])
print(trans)
# Create a rotation quaternion (90 degrees around Y axis)
rot = Quaternion.from_axis_rotation([0.0, 1.0, 0.0], np.pi/2)
print(rot)
# Apply rotation to a vector
vec = Vector3([1, 0, 0])
transformed = rot * vec
print(transformed)