0
$\begingroup$

Rosanswers logo

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?


Originally posted by nbro on ROS Answers with karma: 372 on 2019-03-02

Post score: 0

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

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.


Originally posted by gvdhoorn with karma: 86574 on 2019-03-02

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

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!


Originally posted by jarvisschultz with karma: 9031 on 2019-03-02

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.