This repository contains Python stub files for the CARLA Python API. Installing these along the CARLA Python API will allow you to use type hints and auto-completion in your code.
Download the stub files (ending with .pyi
) for your version of CARLA from the releases page. Then follow the installation instructions for your editor below.
VS code expects by default that custom stubs are placed in the ./typings
directory in your project. Create a subdirectory named carla
(./typings/carla
) and place the stub files there. You should now see type hints for the carla
-module in your code. See VS Code docs of stubPath
for more information.
Create a directory in the root of your project with any name, for example ./stubs
. Right-click the directory and select Mark directory as --> Sources Root. Create a subdirectory named carla
(./stubs/carla
) and place the stub files there. You should now see type hints for the carla
-module in your code. See PyCharm docs of stubs for external implementation for more information.
See if your editor supports adding custom Python stubs. If not, you can add the stub files directly to the CARLA module:
- Run
pip show carla
in the terminal. Find theLocation
path. This should end in a directory namedsite-packages
. - Open the
Location
directory above. Place the stub files in thecarla
subdiretory (.../site-packages/carla
). - You should now see type hints for the
carla
-module in your code.
Stubs are available in releases. You can generate them yourself:
- Clone this repository.
- Install the requirements:
pip install -r requirements.txt
- Run
python -m src.generate_stubs
in the terminal. This will generate stubs for the latest CARLA version. You can specify a different version by runningpython -m src.generate_stubs --version <version>
. Seepython -m src.generate_stubs --help
for more information.