Install & Compatibility
Where this runs
tested against v1.6.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.116s · 27.7MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.7s · import 0.094s · 29MB
30MB installed
● package 30MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
RosPack
✓ from rospkg import RosPack
ResourceNotFound
✓ from rospkg.common import ResourceNotFound
✗ from rospkg import ResourceNotFound
ResourceNotFound is in rospkg.common, not directly under rospkg.
This quickstart demonstrates how to initialize `RosPack` to find the path of a ROS package (`rospy`), list its dependencies (`roscpp`), and check for the existence of a package. It includes error handling for `ResourceNotFound`.
import rospkg
import os
try:
# Initialize RosPack to query ROS packages
r = rospkg.RosPack()
# Get the path to a package, e.g., 'rospy'
rospy_path = r.get_path('rospy')
print(f"Path to rospy package: {rospy_path}")
# List direct dependencies of a package, e.g., 'roscpp'
# Note: 'roscpp' is typically a C++ package, but rospkg can still find its dependencies
try:
roscpp_depends = r.get_depends('roscpp')
print(f"Dependencies of roscpp: {roscpp_depends}")
except rospkg.ResourceNotFound:
print("roscpp package not found, cannot list dependencies. Is a ROS environment sourced?")
# Check if a package exists
if r.has_package('rospy'):
print("rospy package exists.")
except rospkg.ResourceNotFound as e:
print(f"Error: ROS resource not found: {e}. Ensure ROS environment is sourced correctly.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingrospkg is not API compatible with older `roslib` modules it replaced (e.g., `roslib.manifest`, `roslib.packages`). Direct migration from `roslib` APIs will require code changes.fixReview REP 114 for details on API changes. Adapt code to use `rospkg.RosPack` and `rospkg.Manifest` classes directly, noting changes in method signatures and return types (e.g., `get_depends` now takes a single package argument and returns a list of dependencies).
affects: All versions since rospkg's inception (REP 114 in 2011)
gotchaThe `rospkg.ResourceNotFound` exception is commonly encountered if the ROS environment is not properly sourced (e.g., `setup.bash` not run) or the requested package does not exist within the active ROS workspace or installed distribution.fixEnsure that the ROS environment setup file (e.g., `source /opt/ros/<distro>/setup.bash` or `source ~/catkin_ws/devel/setup.bash`) is executed in the shell where the Python script is run. Verify the package name is correct and the package is indeed discoverable by ROS.
affects: All versions
gotchaWhile `pip install rospkg` is standard, in a full ROS installation, `rospkg` is often installed as a system dependency via `apt` (e.g., `sudo apt-get install python3-rospkg`). Mixing `pip` and `apt` installations of `rospkg` or its dependencies can lead to conflicts and unexpected behavior, especially in complex ROS environments.fixPrefer the package manager (e.g., `apt`) provided by your ROS distribution if you are working within a standard ROS setup. Use `pip` only if you are in a standalone Python environment or if explicitly instructed for a specific ROS development workflow, ensuring virtual environments are used to isolate dependencies.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'rospkg'
The `rospkg` library is not installed in the Python environment being used or is not accessible via `PYTHONPATH`.
fixInstall `rospkg` using pip (e.g., `pip install rospkg` or `pip3 install rospkg`) or through your system's package manager for ROS installations (e.g., `sudo apt-get install python3-rospkg` for ROS Noetic).
rospkg.ResourceNotFound: The resource 'some_package_name' could not be found.
The specified ROS package either does not exist, is misspelled, or is not currently discoverable within the active ROS environment's `ROS_PACKAGE_PATH`.
fixVerify the package name's spelling, ensure the package exists on your system, and confirm that your ROS environment (e.g., `source /opt/ros/<distro>/setup.bash`) is correctly sourced.
AttributeError: module 'rospkg' has no attribute 'get_path'
The `get_path` method is part of the `RosPack` class and must be called on an instance of `RosPack`, not directly from the `rospkg` module.
fixInstantiate the `RosPack` class first, then call `get_path` on that instance: `import rospkg; rp = rospkg.RosPack(); path = rp.get_path('your_package_name')`. rospkg.ResourceNotFound: The resource '[package_name]' could not be found among the available packages.
The specified ROS package cannot be found by 'rospkg', usually because it's not in the 'ROS_PACKAGE_PATH' or the ROS environment setup script has not been sourced.
fixEnsure your ROS environment is sourced (e.g., `source /opt/ros/<distro>/setup.bash` or `source ~/catkin_ws/devel/setup.bash`) and verify the package name and its presence in a directory included in `ROS_PACKAGE_PATH`.
rospkg.ResourceNotFound: rosresource not found
rospkg cannot locate fundamental ROS resources, typically due to an improperly configured or unsourced ROS environment (e.g., `ROS_ROOT` or `ROS_PACKAGE_PATH` are unset or incorrect).
fixEnsure your ROS environment is fully sourced by running the appropriate setup script (e.g., `source /opt/ros/<distro>/setup.bash` or `source ~/catkin_ws/devel/setup.bash`).
Upgrade
Version history
1.6.1latest on PyPI · released Dec 19, 2025
Audit
Dependencies
No dependency data recorded yet.