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

How to install my Python modules as part of my ROS package

asked 2020-05-01 13:27:25 -0500

billmania gravatar image

updated 2020-05-01 13:39:04 -0500

gvdhoorn gravatar image

I'm using:

ROS Melodic

ubuntu 18.04

Python 3.6.9

My ROS project name is "ros_moos" and my Python package name is "ros_moos".

My directory structure under ~/catkin_ws/src/ros_moos is:

├── CMakeLists.txt
├── launch
│   └── ros_moos.launch
├── LICENSE
├── msg
│   ├── AuvMove.msg
│   ├── AuvPose.msg
│   ├── AuvSafety.msg
│   └── AuvSystems.msg
├── nodes
│   ├── ros_moos
│   │   ├── auv_control.py
│   │   ├── auv_status.py
│   │   ├── __init__.py
│   │   ├── moos_ros.py
│   │   ├── moos_test.py
│   │   └── uuv_moos.py
│   └── tests
├── package.xml
├── params
│   └── auv_params.yaml
├── README.md
├── requirements.txt
└── setup.py

setup.py contains:

from setuptools import setup
from catkin_pkg.python_setup import generate_distutils_setup

setup_args = generate_distutils_setup(
    version="0.0.1",
    packages=['ros_moos'],
    package_dir={'': 'src'})

setup(**setup_args)

In the CMakeLists.txt I have catkin_python_setup() enabled. I build the project with "catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3" and there are no errors.

roslaunch can find my ROS package and start my two Python nodes, auv_control.py and auv_status.py. rostopic and rosmsg can find the definitions for AuvPose and the other messages.

The problem is the other Python modules, moos_ros.py and uuv_moos.py are NOT installed into the /devel/ environment and auv_status.py can't import those modules when started by roslaunch.

According to https://docs.ros.org/api/catkin/html/... and https://docs.ros.org/api/catkin/html/... I've done what's required.

Is this a known issue or need I do something more?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2020-05-04 17:16:10 -0500

billmania gravatar image

Thanks to a nudge and some suggestions from Jarvis Schultz I found the problem with my setup. In my definition of the package_dir argument in setup.py, I incorrectly put 'src'. Since my nodes and their supporting Python modules are in "nodes" and not in "src", an update to that argument solved the problem.

After the correction, I verified that I can import moos_ros.py and uuv_moos.py in both the devel and the install environments.

edit flag offensive delete link more
0

answered 2020-05-01 16:52:21 -0500

ahendrix gravatar image

From: https://docs.ros.org/api/catkin/html/...

Standard ROS practice is to place Python modules under the src/your_package subdirectory, making the top-level module name the same as your package. Python requires that directory to have an __init__.py file, too.

Your python library sources are in nodes/ros_moos ; you should move them to src/ros_moos

edit flag offensive delete link more

Comments

A few paragraphs earlier in that same document one can find "Standard ROS practice is to place all executable Python programs in a package subdirectory named nodes/ or scripts/." In my project, nodes/ros_moos/auv_status.py is a Python executable program used as a ROS node by roslaunch. Does it belong under nodes or src?

nodes/ros_moos/uuv_moos.py is only a Python module and not a ROS node. It's imported by auv_status.py. Must it and its ilk be moved to src/ros_moos and an __init__.py added to src/ros_moos?

The following still doesn't make moos_ros.py and uuv_moos.py import-able.

├── nodes
│   ├── ros_moos
│   │   ├── auv_control.py
│   │   ├── auv_status.py
│   │   ├── __init__.py
│   │   └── moos_test.py
│   └── tests
├── package.xml
├── params
│   └── auv_params.yaml
├── README.md
├── requirements.txt
├── setup.py
└── src
    └── ros_moos
        ├── __init__.py
        ├── moos_ros.py
        └── uuv_moos.py
billmania gravatar image billmania  ( 2020-05-01 17:12:03 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2020-05-01 13:27:25 -0500

Seen: 1,422 times

Last updated: May 04 '20