Skip to content

fix(python): expose carla.command namespace on ue5 module layout (#9634 PR #0u) - #9775

Merged
Blyron merged 4 commits into
carla-simulator:ue5-devfrom
youtalk:fix/carla-command-namespace
Jun 29, 2026
Merged

Blyron merged 4 commits into
carla-simulator:ue5-devfrom
youtalk:fix/carla-command-namespace

Conversation

@youtalk

@youtalk youtalk commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Description

Makes from carla.command import ... work on the ue5-dev Python API. This is the C++ binding half of issue #9634 PR #0u (the Python-agent half is #9774); the two are independent and target ue5-dev directly.

On ue5-dev the installed wheel ships carla as a single bare extension module (carla.cpython-*.so), not a package — so PythonAPI/carla/__init__.py is never executed at import time and a sys.modules shim placed there is dead code. The fix is a one-line change in the binding: registering the command submodule as "carla.command" via PyImport_AddModule places it directly in sys.modules, which is exactly what from carla.command import ... resolves against. scope().attr("command") = command_module is unchanged, so carla.command.X attribute access keeps working, and the command classes now report __module__ == 'carla.command'.

Ported from ue4-dev commit aeeff9907 (#8161), reworked for the ue5 module layout. Fixes #6414 on ue5-dev.

Part of #9634 (PR #0u).

Where has this been tested?

  • Platform(s): Ubuntu Linux
  • Python version(s): 3.12
  • Unreal Engine version(s): UE 5.5 (CARLA fork)

Rebuilt carla-python-api and reinstalled the wheel, then verified against a fresh interpreter (no manual sys.modules injection):

  • from carla.command import SpawnActor, DestroyActor succeeds.
  • carla.command.SpawnActor.__module__ == 'carla.command'; 'carla.command' in sys.modules is True.
  • carla.command.FutureActor == 0 (attribute access regression check passes).
  • from carla.command import SpawnActor as S; S is carla.command.SpawnActorTrue.

Possible Drawbacks

  • The submodule's reported __module__ changes from libcarla.command to carla.command; this is the intended correction and matches how the module is imported.

This change is Reviewable

youtalk added 2 commits June 3, 2026 11:41
The ue5-dev wheel installs `carla` as a single extension module
(carla.cpython-*.so), not a package, so PythonAPI/carla/__init__.py is
never executed at import time. Registering the command submodule as
"carla.command" via PyImport_AddModule places it directly in
sys.modules, which makes `from carla.command import ...` work without
any __init__.py shim. Verified: from carla.command import SpawnActor,
DestroyActor; carla.command.SpawnActor.__module__ == 'carla.command'.

Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
@youtalk
youtalk marked this pull request as ready for review June 3, 2026 18:47
@youtalk
youtalk requested a review from a team as a code owner June 3, 2026 18:47
Copilot AI review requested due to automatic review settings June 3, 2026 18:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the Python API’s command submodule registration so carla.command becomes the canonical import path (instead of libcarla.command), and documents the change in the changelog.

Changes:

  • Register the Boost.Python command submodule under carla.command.
  • Document the import-path fix in CHANGELOG.md.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
PythonAPI/carla/src/Commands.cpp Changes the registered Python submodule name to carla.command.
CHANGELOG.md Notes the Python import-path fix and rationale for UE5 wheels.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PythonAPI/carla/src/Commands.cpp
Comment thread PythonAPI/carla/src/Commands.cpp
Comment thread CHANGELOG.md
@youtalk

youtalk commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

@LuisPovedaCano @Blyron Could you review this?

@JArmandoAnaya

Copy link
Copy Markdown
Contributor

Hello @youtalk, you have some conflicts here. This PR need to be rebased from upstream ue5-dev.

@youtalk

youtalk commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@JArmandoAnaya I've merged the latest ue5-dev.

@youtalk

youtalk commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@Blyron Could you merge this?

@Blyron

Blyron commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

once the pipeline passes

@Blyron
Blyron merged commit 6019663 into carla-simulator:ue5-dev Jun 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CARLA 0.9.14 - PythonAPI - ModuleNotFoundError: No module named 'carla.libcarla.command'

5 participants