ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Finding Python modules in groovy and with catkin?

asked 2013-01-16 11:44:46 -0500

TommyP gravatar image

Suppose I have a package with two sub directories "src" and "test". Suppose I have a module "" in "src". How do I in a script in "test" import from ""? What is the correct method with regard to finding "" when executing?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2013-01-16 23:06:46 -0500

KruseT gravatar image

updated 2013-01-18 03:47:45 -0500

The recommended method is to use the nosetests library to write tests fpr python. The command is nose. Nose automatically sets the PYTHONPATH before running the tests when you use reasonable names for your folders, like src and test. Doing so, in a python file in the test folder you can simply write "import" to import a module defined in src/foo/

When you write python modules with catkin, you should also use a file and the catkin_python_setup macro in your CMakeLists.txt file. More information can be found in the catkin documentation, and rospy tutorials, such as here: and here:

edit flag offensive delete link more


I found an example file and got that to work. But I do not understand exactly what it does. Are there any documentation for Especially I did not get what the "packages" parameter was supposed to be.

TommyP gravatar image TommyP  ( 2013-01-17 00:27:42 -0500 )edit
1 is the standard build file for python projects. In our case, you declare the scripts and packages from your project, and makes sure those get installed to the right locations. More info here:

KruseT gravatar image KruseT  ( 2013-01-18 03:47:29 -0500 )edit

So are you saying that the thing in "packages" in is not ros packages at all? Are they Python packages or what are they? And if they are ROS packages what is a "relay package" talked about on the web page you gave? (Re-reading this now after reading the SIG discussion about

TommyP gravatar image TommyP  ( 2013-02-07 00:32:24 -0500 )edit

yes, 'packages' in the relate to python packages only. And a relay-package is a folder foo with only an file in it that points to the foo folder in the sourcespace with all the python code the user writes.

KruseT gravatar image KruseT  ( 2013-02-07 01:50:19 -0500 )edit

what happens if you accidentally run the file the tutorial said it can break your ROS installation? Does this mean you have to reinstall ROS if you do this? Is it possible to keep a back up of your ROS workspace and just replace it?

Sentinal_Bias gravatar image Sentinal_Bias  ( 2014-04-02 00:33:55 -0500 )edit

You should ask this as a separate question. The answer is complicated. Nothing will break immediately, but maintenance problems will likely arise later on. Solution: remove all the files created.

joq gravatar image joq  ( 2014-04-02 03:27:34 -0500 )edit

Question Tools

1 follower


Asked: 2013-01-16 11:44:46 -0500

Seen: 1,085 times

Last updated: Jan 18 '13