Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Box2D
✓ from Box2D import b2World
The top-level module is 'Box2D' (capital B, capital D).
b2World
✓ from Box2D import b2World
✗ from box2d import b2World
Package name is 'box2d' (lowercase), but the module is 'Box2D' (capital letters).
Creates a simple falling circle simulation.
from Box2D import b2World, b2Vec2, b2BodyDef, b2_dynamicBody, b2CircleShape, b2FixtureDef
import math
world = b2World(gravity=b2Vec2(0, -10))
body_def = b2BodyDef()
body_def.type = b2_dynamicBody
body_def.position.Set(0, 10)
body = world.CreateBody(body_def)
circle = b2CircleShape(radius=1)
fixture_def = b2FixtureDef(shape=circle, density=1, friction=0.3)
body.CreateFixture(fixture_def)
for i in range(60):
world.Step(1/60, 6, 2)
print(body.position.y)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'box2d'
Importing from 'box2d' (lowercase) but the correct module is 'Box2D'.
AttributeError: module 'Box2D' has no attribute 'b2World'
Usually due to a broken installation or mismatched package versions; also can happen if importing from 'Box2D' but the library is not properly installed.
fixReinstall via 'pip install --upgrade box2d' and verify import using 'import Box2D; print(dir(Box2D))'.
Upgrade
Version history
2.3.10latest on PyPI · released Apr 11, 2020
Audit
Dependencies
No dependency data recorded yet.