ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Current python workpath is where you run rosrun, not the …/test/src. Hence, this problem is coursed by the path of python file you want import is not in sys.path, you can simply fix it by add sys.path.append("pyth to test2.py") to test1.py.
Also, when adding test1.py to CMakeLists.txt, ROS noetic will create a .py file in devel/lib with same name and add the file path to sys.path, then rosrun test test1 is available. So if you adding test2.py to CMakeLists.txt, you may get error like module test2 has no attribute test.