{"id":8470,"library":"pybullet","title":"PyBullet","description":"PyBullet is the official Python interface for the Bullet Physics SDK, offering real-time collision detection and multi-physics simulation. It is widely used in robotics simulation, reinforcement learning, and virtual reality research and applications. PyBullet allows loading articulated bodies from various file formats like URDF, SDF, and MJCF, and provides functionalities for forward dynamics, inverse dynamics, forward and inverse kinematics, and collision detection. The library is actively maintained with frequent updates to its underlying C++ Bullet Physics engine.","status":"active","version":"3.2.7","language":"en","source_language":"en","source_url":"https://github.com/bulletphysics/bullet3","tags":["robotics","simulation","reinforcement-learning","physics","collision-detection","kinematics"],"install":[{"cmd":"pip install pybullet","lang":"bash","label":"Install PyBullet"}],"dependencies":[{"reason":"Provides common URDF models and textures for simulations (e.g., planes, robots, objects).","package":"pybullet_data","optional":true}],"imports":[{"note":"It is conventional to import pybullet as 'p' for brevity in API calls.","wrong":"import pybullet","symbol":"pybullet","correct":"import pybullet as p"},{"note":"Required to access common assets like 'plane.urdf' or 'r2d2.urdf'.","symbol":"pybullet_data","correct":"import pybullet_data"}],"quickstart":{"code":"import pybullet as p\nimport pybullet_data\nimport time\n\n# Connect to the physics engine in GUI mode\n# Use p.DIRECT for non-graphical (headless) mode\nphysicsClient = p.connect(p.GUI)\n\n# Set additional search path for URDF files (e.g., plane.urdf, r2d2.urdf)\np.setAdditionalSearchPath(pybullet_data.getDataPath())\n\n# Set gravity\np.setGravity(0, 0, -10)\n\n# Load a plane\nplaneId = p.loadURDF(\"plane.urdf\")\n\n# Load a simple robot (e.g., R2D2)\nrobotStartPos = [0, 0, 1]\nrobotStartOrientation = p.getQuaternionFromEuler([0, 0, 0])\nrobotId = p.loadURDF(\"r2d2.urdf\", robotStartPos, robotStartOrientation)\n\n# Run the simulation for a few steps\nprint(\"Simulating...\")\nfor i in range(1000):\n    p.stepSimulation()\n    time.sleep(1./240.) # PyBullet's default timestep is 1/240 seconds\n\n# Disconnect from the simulator\np.disconnect()\nprint(\"Simulation finished.\")","lang":"python","description":"This quickstart initializes a PyBullet simulation in graphical mode, sets gravity, loads a ground plane and a simple robot model (R2D2), then runs the simulation for a short duration before disconnecting. It demonstrates the basic lifecycle of a PyBullet application."},"warnings":[{"fix":"Ensure C++ build tools are installed (e.g., Visual C++ Build Tools on Windows, Xcode command line tools on macOS, `build-essential` on Linux). Consider using a Python version for which wheels are readily available (e.g., 3.6-3.11 for x64 Linux).","message":"Installing PyBullet on systems other than x64 Linux (e.g., macOS with Apple Silicon, or Windows without Visual C++ build tools) or with very recent Python versions (e.g., 3.12+) may fail due to a lack of pre-built wheels, requiring local compilation.","severity":"gotcha","affected_versions":"All versions, especially for non-standard environments or newer Python releases."},{"fix":"Upgrade PyBullet to version 3.2.5 or newer to avoid this memory leak issue. [cite: github_release_notes]","message":"Earlier versions (prior to 3.2.4/3.2.5) had a bug causing memory buildup when repeatedly using `createMultiBody` due to improper memory handling in some concave collision early-out reverts.","severity":"breaking","affected_versions":"< 3.2.4"},{"fix":"To disable file caching, use `p.setPhysicsEngineParameter(enableFileCaching=0)` after connecting to the physics client.","message":"PyBullet's internal file caching can sometimes interfere with testing or dynamic asset loading if assets change. By default, PyBullet caches loaded files to speed up subsequent loads.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the necessary C++ build tools for your system (e.g., `build-essential` on Linux, Xcode command line tools on macOS, Microsoft Visual C++ Build Tools on Windows). Alternatively, try installing PyBullet within a Python virtual environment that uses a Python version known to have pre-built wheels for your platform.","cause":"This error typically occurs during `pip install pybullet` when no pre-built wheel (binary distribution) is available for your specific Python version and/or operating system/architecture. This forces pip to attempt building from source, which requires a C++ compiler toolchain.","error":"ERROR: Failed building wheel for pybullet"},{"fix":"Ensure that the `PYTHONPATH` environment variable is correctly set to include the directory containing the compiled `pybullet.so` (or equivalent) file. For example: `export PYTHONPATH=/your_path_to_bullet/build_cmake/examples/pybullet:$PYTHONPATH`.","cause":"This `ImportError` usually happens after a manual compilation of PyBullet from source, indicating that the Python interpreter cannot find or correctly load the compiled shared library (e.g., `pybullet.so` on Linux/macOS, `_pybullet.pyd` on Windows) or its dependencies.","error":"ImportError: .../pybullet.so: undefined symbol: ..."}]}