Ask Your Question

What is the difference between rospkg and rospack?

asked 2019-03-02 12:36:50 -0500

nbro gravatar image

updated 2019-03-02 12:37:06 -0500

I know I can import rospkg from a Python script. rospack is a system utility which I can invoke from the command-line. What are the differences between these two tools?

The documentation of rospkg states

The rospkg Python module provides basic utilities for querying information about ROS packages, stacks, and distributions.

The rospack page states

rospack is a command-line tool for retrieving information about ROS packages available on the filesystem

They seem to be doing similar things. So, why do we need both (if they are different)? When do I need one but not the other?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2019-03-02 14:34:06 -0500

The summaries that you provided are correct, and seem to me to accurately describe the purpose of both tools. Your assertion that they do similar things is correct, but the situations where you would use one or the other is quite different.

The most common use of rospack is (as stated) a command line tool. If you are trying to figure out what dependencies you might be missing to use a package, if you wanted to understand what plugins a package exports, or if you wanted to see where a package is installed, all of these questions could be answered with rospack at the command line.

rospkg on the other hand would likely not be directly used by a developer to answer queries, but would instead be incorporated directly into a Python script to provide functionality that depends on querying information about installed ROS packages. I've occasionally seen people use this capability in writing installation or setup scripts that support a ROS project, but the more common place I've seen this is to find out the paths to a package within a node. For example, let's say you wanted to read a config file in Python that you knew was in a package's directory, then you could use rospkg to automatically get the path to the package's root directory and find that config file in a portable way.

Hope that helps!

edit flag offensive delete link more

answered 2019-03-02 14:28:47 -0500

gvdhoorn gravatar image

updated 2019-03-02 14:29:42 -0500

One is a Python module, the other a command line tool, which offer similar (but not identical) functionality, as you already notice.

So, why do we need both (if they are different)? When do I need one but not the other?

I cannot import a C++ command line utility into my Python script.

Neither can I use a Python module as a command line binary from my shell scripts.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-03-02 12:36:50 -0500

Seen: 149 times

Last updated: Mar 02 '19