# ImportError: No module named 'my_package' when running colcon build --packages-select my_package

- **ID:** `ros2/colcon-build-python-import-error-no-module-named-package`
- **Domain:** ros2
- **Category:** build_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The Python package in the ROS2 workspace is missing a __init__.py file or has an incorrect package structure, causing colcon to fail to import it during build.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| ROS2 Humble | active | — | — |
| ROS2 Iron | active | — | — |
| colcon-core 0.13.x | active | — | — |
| colcon-ros 0.5.x | active | — | — |

## Workarounds

1. **Create an empty __init__.py file in the package's source directory: 'touch src/my_package/my_package/__init__.py'** (95% success)
   ```
   Create an empty __init__.py file in the package's source directory: 'touch src/my_package/my_package/__init__.py'
   ```
2. **Verify the package structure: the source directory should contain a subdirectory with the same name as the package, containing __init__.py and other modules.** (90% success)
   ```
   Verify the package structure: the source directory should contain a subdirectory with the same name as the package, containing __init__.py and other modules.
   ```

## Dead Ends

- **** — The import error is specific to the package; building all packages may mask the issue or fail elsewhere. (60% fail)
- **** — The error is due to missing __init__.py, not build artifacts; deleting build won't fix it. (90% fail)
- **** — While this may install the package, it bypasses colcon's build system and may cause inconsistencies in the workspace. (70% fail)
