ROS Package Library

1.6.1 · active · verified Tue Apr 14

rospkg is a standalone Python library for the ROS (Robot Operating System) package system. It provides utilities for querying information about ROS packages, stacks, and distributions, abstracting the underlying filesystem layout. The current version is 1.6.1, with releases occurring every few months to once a year, reflecting active but measured development.

Warnings

Install

Imports

Quickstart

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}")

view raw JSON →