{"id":6226,"library":"rospkg","title":"ROS Package Library","description":"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.","status":"active","version":"1.6.1","language":"en","source_language":"en","source_url":"https://github.com/ros-infrastructure/rospkg","tags":["ROS","robotics","package management","filesystem","roslib"],"install":[{"cmd":"pip install rospkg","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"RosPack","correct":"from rospkg import RosPack"},{"note":"ResourceNotFound is in rospkg.common, not directly under rospkg.","wrong":"from rospkg import ResourceNotFound","symbol":"ResourceNotFound","correct":"from rospkg.common import ResourceNotFound"}],"quickstart":{"code":"import rospkg\nimport os\n\ntry:\n    # Initialize RosPack to query ROS packages\n    r = rospkg.RosPack()\n\n    # Get the path to a package, e.g., 'rospy'\n    rospy_path = r.get_path('rospy')\n    print(f\"Path to rospy package: {rospy_path}\")\n\n    # List direct dependencies of a package, e.g., 'roscpp'\n    # Note: 'roscpp' is typically a C++ package, but rospkg can still find its dependencies\n    try:\n        roscpp_depends = r.get_depends('roscpp')\n        print(f\"Dependencies of roscpp: {roscpp_depends}\")\n    except rospkg.ResourceNotFound:\n        print(\"roscpp package not found, cannot list dependencies. Is a ROS environment sourced?\")\n\n    # Check if a package exists\n    if r.has_package('rospy'):\n        print(\"rospy package exists.\")\n\nexcept rospkg.ResourceNotFound as e:\n    print(f\"Error: ROS resource not found: {e}. Ensure ROS environment is sourced correctly.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"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`."},"warnings":[{"fix":"Review 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).","message":"rospkg 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.","severity":"breaking","affected_versions":"All versions since rospkg's inception (REP 114 in 2011)"},{"fix":"Ensure 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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Prefer 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.","message":"While `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z","problems":[]}