ROS not detecting the Python file in docker image

asked 2021-05-04 17:56:42 -0500

iamrandom gravatar image

updated 2021-05-04 18:21:13 -0500

ROS & Python Versions: Noetic (Dockerized), Python 3.8.5

Problem: I am trying to run a python script using rosrun.

bash rosrun vision vision_main.py

I come across the following error message:

Traceback (most recent call last):
  File "/ws/devel/lib/vision/vision_main.py", line 15, in <module>
    exec(compile(fh.read(), python_script, 'exec'), context)
  File "/ws/src/vision/scripts/vision_main.py", line 5, in <module>
    import Road
ModuleNotFoundError: No module named 'Road'

I've verified that the python files are executables (chmod +x). Additionally, if I run the vision_main.py directly via python3, the code runs fine...

python3 vision_main.py

Any idea why this might be happening?

Directory Structure of src:

src/
├── CMakeLists.txt -> /opt/ros/noetic/share/catkin/cmake/toplevel.cmake
└── vision
    ├── CMakeLists.txt
    ├── package.xml
    └── scripts
        ├── road.py
        └── vision_main.py

Python Code for vision_main.py file:

#!/usr/bin/env python

import sys
import rospy
from road import Road

if __name__ == '__main__':
    rospy.init_node('vision_node', anonymous=True)
    rd = Road()
    rospy.spin()
edit retag flag offensive close merge delete

Comments

Please show the Dockerfile.

It's like you're not source-ing the setup.bash (correctly) before trying to run your .py.

gvdhoorn gravatar image gvdhoorn  ( 2021-05-05 00:24:10 -0500 )edit