ROS package that contains python package with a subpackage is not installed properly
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 (a.py
).
Here is example file structure:
my_ws/src/ros_pkg/
CMakeLists.txt
package.xml
setup.py
src/
my_pkg/
__init__.py
a.py
my_subpkg/
__init__.py
b.py
Content of the setup.py
file:
#!/usr/bin/env python
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
setup_args = generate_distutils_setup(
packages=[
'my_pkg',
],
package_dir={'': 'src'}
)
setup(**setup_args)
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_ws/install/lib/python2.7/dist-packages/my_pkg/
__init__.py
a.py
# 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 devel
workspace when working with ROS, however, I also use Industrial CI (https://github.com/ros-industrial/ind...) 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?
Following references may be helpful.