ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

ROS package that contains python package with a subpackage is not installed properly

asked 2022-08-01 13:50:24 -0600

BlazP gravatar image

I have ROS package that contains a python package with a subpackage (nested python package). When I build the ROS package and source devel workspace, I can import the subpackage as expected. However if I source install workspace I cannot import subpackge anymore, only module of the outer python package (

Here is example file structure:


Content of the file:

#!/usr/bin/env python
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

setup_args = generate_distutils_setup(
    package_dir={'': 'src'}

Steps to reproduce:

Setup basic ROS package containing python package as provided in example file structure Then build it.

catkin config --install
catkin build my_pkg

Source devel workspace and try to import nested module in python (it works).

source devel/setup.bash
python -c 'from my_pkg import a'  # Works

Now source install workplace (in fresh shell) and try to import it again. It fails.

source devel/setup.bash
python -c 'from my_pkg import a'  # Works
python -c 'from my_pkg.my_subpkg import b'  # Fails (ImportError: No module named my_subpkg)

As suspected, there is no python subpackage in the install workspace (my_ws/install/lib/python2.7/dist-packages /my_pkg/)

    # my_subpkg/ is not here

I tested it on python 2 and 3 (ROS melodic and noetic).

Can anyone tell me how to achieve that the subpackage would be accessible when the install workspace is sourced?

Full story: I normally source develworkspace when working with ROS, however, I also use Industrial CI ( where tests are run based on install workspace (if I am not mistaken), which consequentially fails in that case. So if catkin cannot be configured to avoid this issue, maybe Industrial CI can be tweaked to pass tests?

edit retag flag offensive close merge delete


1 Answer

Sort by » oldest newest most voted

answered 2022-08-09 02:21:35 -0600

Mathias Lüdtke gravatar image

This is not a problem with catkin or CI, you just have to fix your


Keep in mind that although package_dir applies recursively, you must explicitly list all packages in packages: the Distutils will not recursively scan your source tree looking for any directory with an file

catkin does not offer any special support here (

Note: As in setuptools, the packages list is not recursive, and sub-packages must be included explicitly (e.g. which would contain the python modules defined in the folder src/your_package/tools/my_util/, along with an file)

If you want my_pkg.my_subpkg to get installed, you have to list it explicitly.

edit flag offensive delete link more


Thank you very much. This is exactly what I needed.

BlazP gravatar image BlazP  ( 2022-08-09 10:31:25 -0600 )edit

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: 2022-08-01 13:46:43 -0600

Seen: 69 times

Last updated: Aug 09