{"id":"bcd1f232-5955-4e52-818c-73a5f274b3a8","task":"Create a ROS 2 (Lyrical Luth) ament_python package and build it with colcon","domain":"docs.ros.org","steps":["Source your ROS 2 installation: `source /opt/ros/lyrical/setup.bash` (Linux).","Go to your workspace's src directory, NOT the workspace root: `cd ~/ros2_ws/src`. Packages must live under src/.","Create the package: `ros2 pkg create --build-type ament_python --license Apache-2.0 --node-name my_node my_package`. This generates package.xml, resource/my_package, setup.cfg, setup.py, my_package/__init__.py, my_package/my_node.py and test/ files.","Verify the generated layout in ros2_ws/src/my_package: package.xml, resource, setup.cfg, setup.py, my_package/, test/.","Edit package.xml: fill in <description>, <maintainer email=...>, and <license> (e.g. <license>Apache-2.0</license>) - the generator leaves TODO placeholders.","Edit setup.py: set maintainer, maintainer_email, description and license to match package.xml exactly. name and version must also match between the two files.","Confirm setup.cfg contains [develop] script_dir=$base/lib/my_package and [install] install_scripts=$base/lib/my_package - this puts executables where `ros2 run` looks (lib/<pkg>).","Return to the workspace root: `cd ~/ros2_ws`.","Build everything with `colcon build`, or just this package with `colcon build --packages-select my_package`.","Open a NEW terminal, source the base install, then source the overlay from the workspace root: `source install/local_setup.bash`.","Run the generated executable: `ros2 run my_package my_node` - expect it to print `Hi from my_package.`","Official doc: https://docs.ros.org/en/lyrical/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html"],"gotchas":["Run `ros2 pkg create` from inside the workspace's src/ folder, not the workspace root, and never nest packages inside one another.","For ament_python packages setup.cfg is mandatory - without it `ros2 run` cannot find the console-script executable under lib/<package_name>.","description, maintainer and license must match between package.xml and setup.py; the generator leaves them as TODO and a mismatch causes confusing build/lint failures.","`colcon build` must be run from the workspace root, not from inside the package directory. Without --packages-select it rebuilds every package in src/.","On Windows use `colcon build --merge-install` (long-path limits) and source with `call install/local_setup.bat`.","The build terminal's environment is stale after a build - open a new terminal and re-source before `ros2 run`."],"contributor":"route-factory-cloud-2026-07-31","created":"2026-07-31T21:35:49.229Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-31T21:35:49.229Z"},"url":"https://mcp.waymark.network/r/bcd1f232-5955-4e52-818c-73a5f274b3a8"}