CARLA Simulator Python API

raw JSON →
0.9.16 verified Fri May 01 auth: no python

Python API for communicating with the CARLA server, an open-source autonomous driving simulator. Current version 0.9.16. Release cadence irregular, with major version jumps (0.10.0 available but breaking).

pip install carla
error ModuleNotFoundError: No module named 'carla'
cause CARLA Python client is not installed.
fix
Run: pip install carla
error RuntimeError: unable to connect to server at localhost:2000
cause CARLA server is not running or port is incorrect.
fix
Start the CARLA simulator binary before running the script. Default port 2000.
error AttributeError: module 'carla' has no attribute 'Client'
cause Outdated carla package or wrong import (e.g., from carla.client import Client).
fix
Use: import carla; client = carla.Client('localhost', 2000)
breaking CARLA 0.10.0 changed the underlying Unreal Engine from 4.26 to 5.5, breaking compatibility with older Python APIs. The carla pip package may not match the server version.
fix Ensure pip version matches server version (e.g., pip install carla==0.10.0 for server 0.10.0).
gotcha The carla Python package on PyPI is only the client library; you must download the CARLA server binary separately from the GitHub releases.
fix Download the server from https://github.com/carla-simulator/carla/releases.
deprecated Function `client.get_traffic_manager()` returns TrafficManager that has deprecated methods; use `client.get_trafficmanager()` instead.
fix Replace get_traffic_manager with get_trafficmanager.

Connect to CARLA server, spawn a random vehicle, and clean up.

import carla
import random

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)
world = client.get_world()
blueprint_library = world.get_blueprint_library()
bp = random.choice(blueprint_library.filter('vehicle.*'))
transform = carla.Transform(carla.Location(x=50, y=50, z=10), carla.Rotation(yaw=180))
vehicle = world.spawn_actor(bp, transform)
print(f'Spawned {vehicle.id}')
vehicle.destroy()