Manage ROS 2 workspace dependencies using rosdep, pip, and package.xml. Use when asked to install dependencies, setup Python virtual environment, configure package dependencies, or resolve missing dependencies. Supports C++ dependencies, Python packages, tool dependencies, and dependency installation workflows.
Manage workspace dependencies across C++, Python, and system tools using rosdep and pip.
scripts/ros-dep.sh available for automated installationrosdep command available (installed with ROS 2)| Type | Managed By | Configuration | Purpose |
|---|---|---|---|
| Tool Dependencies | rosdep | package.xml build tools | Build system, linters, CI tools |
| C++ Runtime/Build Deps | rosdep | package.xml <depend> | C++ libraries and headers |
| Python Runtime Deps | rosdep or setup.py | package.xml or setup.cfg | Production Python packages |
| Python Dev Deps | uv | pyproject.toml | Development tools, docs, notebooks, and local editable packages |
Complete dependency installation for the workspace.
Navigate to workspace root:
cd <workspace_root>
Run automated dependency installation:
./scripts/ros-dep.sh
This script automatically:
rosdep update (updates package registry)package.xml filesVerify installation completed without errors (check final output)
Installation is complete; proceed to Python venv setup if needed
Isolate Python development dependencies from system Python.
Sync the workspace environment:
uv sync
Activate virtual environment:
source .venv/bin/activate
Verify installation:
python3 -m pytest --version
Deactivate when done:
deactivate
Refresh rosdep package registry (required after ROS updates).
Update rosdep cache:
rosdep update
Verify update completed:
rosdep list | head -20
Add a new C++ library to a package's build/runtime dependencies.
Edit package's package.xml:
nano packages/runtime/<package_name>/package.xml
Add dependency in appropriate section:
<!-- For build-time dependencies -->
<build_depend>new_library</build_depend>
<!-- For runtime dependencies -->
<run_depend>new_library</run_depend>
<!-- For both build and runtime -->
<depend>new_library</depend>
Install the new dependency:
rosdep install --from-paths packages/runtime/<package_name> --ignore-src -y
Rebuild the package:
source scripts/setup.bash
python3 -m colcon build --packages-select <package_name>
Add Python package to development or production use.
For Development Dependencies (pytest, docs, linting):
Add the package to the appropriate dependency group in pyproject.toml
Re-sync the environment:
uv sync
For Production Dependencies (used by package code):
Edit package's setup.py or package.xml:
# For setup.py-based packages:
nano packages/runtime/<package_name>/setup.py
Add to install_requires list in setup.py:
install_requires=[
'existing-package>=1.0',
'new-package>=2.0',
]
OR edit package.xml for rosdep-managed dependencies:
<build_depend>python3-new-package</build_depend>
<run_depend>python3-new-package</run_depend>
Rebuild the package:
source scripts/setup.bash
python3 -m colcon build --packages-select <package_name>
Resolve "package not found" or "library not found" errors.
Identify the missing package from error message
Search rosdep registry:
rosdep search <package_name>
If found in rosdep, add to appropriate package.xml or setup.py
If not in rosdep:
pip search <package_name>Re-install dependencies and rebuild:
./scripts/ros-dep.sh
source scripts/setup.bash
python3 -m colcon build --packages-up-to <package_name>
| File | Purpose | Scope |
|---|---|---|
packages/runtime/*/package.xml | C++ and ROS dependencies per package | Package-level |
packages/runtime/*/setup.py | Python package dependencies | Package-level (Python packages only) |
pyproject.toml | Workspace development dependencies for uv | Workspace-level |
.venv/ | Virtual environment | Local development only |
scripts/ros-dep.sh | Automated dependency installation | Workspace setup |
# Update rosdep registry
rosdep update
# Search for available package
rosdep search <package_name>
# Check if dependency is satisfied
rosdep check --from-paths packages/runtime/<package_name>
# Install dependencies for specific path
rosdep install --from-paths packages/runtime/<package_name> --ignore-src -y
# List all installed system dependencies
rosdep list | grep "^python3"
# Sync workspace dependencies
uv sync
# Activate Python venv
source .venv/bin/activate
# Show installed packages
python3 -m pip list
| Issue | Cause | Solution |
|---|---|---|
| "rosdep: command not found" | ROS 2 not installed | Install ROS 2 Jazzy first |
| "package not found in registry" | Package not in rosdep registry | Use pip or install from source |
| Python package import fails | venv not activated or package not installed | Run uv sync and then source .venv/bin/activate |
| "Permission denied" on install | User lacks write permission | Use sudo or fix directory permissions |
| Circular dependency errors | Package depends on itself transitively | Review package.xml dependencies |
| Stale dependency cache | Old dependency versions cached | Run rosdep update and pip cache purge |
| Version conflicts | Different packages require incompatible versions | Review version constraints and update setup.py |
./scripts/ros-dep.sh helper script in your repository for automated installationpackage.xml templates in ROS 2 documentation or your project for dependency configuration examples