Registry / ai-ml / box2d
library2.3.10pypypi✓ verified 84d ago

Python bindings for Box2D, a 2D physics engine. Version 2.3.10 is the latest. Releases are infrequent; the library is stable but in maintenance mode.

pip install box2d
INSTALL
IMPORT
SIG · BOX2D
B
box2d
ai-mlpythonv2.3.10
harness data pending
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)
Debug
Known issues
gotchaThe import module is 'Box2D' (capital B and D), not 'box2d' (lowercase). The PyPI package name is 'box2d' but the module name uses CamelCase.
fix
Use 'from Box2D import ...' instead of 'from box2d import ...'.
affects: all
deprecatedPython 2 is no longer supported. Ensure you are using Python 3.
fix
Use Python 3.6 or newer.
affects: 2.3.10+
gotchaSetting body position using the 'position' attribute after creation may not work; use SetTransform() instead.
fix
Use body.position.Set(x, y) before creation or body.SetTransform(b2Vec2(x,y), angle) after creation.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'box2d'
Importing from 'box2d' (lowercase) but the correct module is 'Box2D'.
fix
from Box2D import ...
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.
fix
Reinstall 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.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
box2d — pip install box2d · libregistry