Saturday, 9 January 2021

ROS Tinkering - 01: 'package_name' is not a package

PROBLEM:

My source code structure is: ./my_project/app_ws/src/abc/abc.py and abc.py is node abc's entry python module.

My CMakelists.txt says:
    project(abc)

My package.xml says:
   <name>abc</name>

$ rosrun abc abc.py 

Traceback (most recent call last):
   File "/home/xxx/workspace/my_project/install/abc/lib/abc/abc.py", line 35, in <module>
    from abc.srv import LoadExperiment, LoadExperimentResponse

File "/home/xxx/workspace/my_project/install/abc/lib/abc/abc.py", line 35, in <module>
    from abc.srv import LoadExperiment, LoadExperimentResponse
ModuleNotFoundError: No module named 'abc.srv'; 'abc' is not a package


Solution:

ROS cannot handle the same name abc as the package name and same as the entry python module file. So just change the entry python module's name to abc_node.py or something else.