Skip to content

aasewold/carla-python-stubs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CARLA Python Stubs

GitHub all releases

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.

type-hints

Installation

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

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.

PyCharm

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.

Other editors

See if your editor supports adding custom Python stubs. If not, you can add the stub files directly to the CARLA module:

  1. Run pip show carla in the terminal. Find the Location path. This should end in a directory named site-packages.
  2. Open the Location directory above. Place the stub files in the carla subdiretory (.../site-packages/carla).
  3. You should now see type hints for the carla-module in your code.

Generating stubs

Stubs are available in releases. You can generate them yourself:

  1. Clone this repository.
  2. Install the requirements: pip install -r requirements.txt
  3. 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 running python -m src.generate_stubs --version <version>. See python -m src.generate_stubs --help for more information.