I use ros-noetic inside a docker container with ubuntu 20.04
My project-tree loks like this:
catkin_ws
|-src
|-obstacle_detector
|-src
|-obstacle_detector.py
|-yolo.py
|-launch
|-obstacle_detector.launch
|-CMakeLists.txt
|-package.xml
Inside a dockerfile I have:
COPY ./docker/entry-point.sh /
RUN chmod +x /entry-point.sh &&
mkdir -p /root/catkin_ws/src/obstacle_detector/src/ &&
mkdir -p /root/catkin_ws/src/obstacle_detector/launch/ &&
mkdir -p /root/catkin_ws/src/obstacle_detector/data/
COPY ./src/* /root/catkin_ws/src/obstacle_detector/src/
COPY ./CMakeLists.txt /root/catkin_ws/src/obstacle_detector/
COPY ./package.xml /root/catkin_ws/src/obstacle_detector/
COPY ./launch/* /root/catkin_ws/src/obstacle_detector/launch/
COPY ./data/* /root/catkin_ws/src/obstacle_detector/data/
RUN apt update &&
source "/opt/ros/$ROS_DISTRO/setup.bash" -- &&
cd /root/catkin_ws &&
apt install -y build-essential gcc &&
catkin_make
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.0.2)
project(obstacle_detector)
catkin_package(
)
include_directories(
)
catkin_install_python(PROGRAMS
src/obstacle_detector.py
src/yolo.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
install(DIRECTORY launch
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})
entry-point.sh sources catkin_ws/devel/setup.sh
yolo.py contains a class Yolo.
obstacle_detector imports it and tries to use it.
catkin_make works without errors. But when I try to use roslaunch src/obstacle_detector/launch/obstacle_detector.launch
I get an error: AttributeError: module 'yolo' has no attribute 'Yolo'
I have a very look-like example of a projects which actualy works and I don’t understand what is wrong here.
This is what’s inside of catkin_ws/devel/lib/obstacle_detector/yolo.py
:
python_script = '/root/catkin_ws/src/obstacle_detector/src/yolo.py'
with open(python_script, 'r') as fh:
context = {
'__builtins__': __builtins__,
'__doc__': None,
'__file__': python_script,
'__name__': __name__,
'__package__': None,
}
exec(compile(fh.read(), python_script, 'exec'), context)
Thanks in advance.