ImportError with Python - Unit 3 - Unit Testing with ROS

Hi The Construct team,

I am currently learning Unit 3: ROS-Node Level Tests in the course Unit Testing with ROS.

In the very first exercise, 3.1 - rotate_robot_test_ros.py, this line gives me an ImportError.

from robot_control.rotate_robot import RobotControl

I tried several combinations, but still keeps failing.

Here is my folder structure:
Screenshot from 2022-11-07 20-40-45

The __init__.py script file is completely blank.

I am not sure if the example code has errors or I am having some folder structure errors.
I can provide additional info if necessary.

Please help!

Thanks,
Girish

UPDATE: Tried some techniques described in this link: 6. Modules — Python 3.11.0 documentation

But I still keep getting ImportError. I have no idea how to proceed at the moment.

– Girish

UPDATE: Even older files that worked a few days back are now failing.

They fail at the same line:

from robot_control.rotate_robot import RobotControl

with the same error message:

user:~/catkin_ws/src/robot_control/test$ python ./rotate_robot_test.py
Traceback (most recent call last):
  File "./rotate_robot_test.py", line 3, in <module>
    from robot_control.rotate_robot import RobotControl
ImportError: No module named robot_control.rotate_robot

The file rotate_robot_test.py was working just 3 days back. Today it is not working.
Not just this file, but all the files that have the import line mentioned above.
There seems to be something wrong with the course environment at this point.
Something updated or something got reset or removed.

At this point, I cannot continue with the course. Someone please fix this soon!

– Girish

Hello @girishkumar.kannan ,

I did get the same error on a first try, but after compiling and sourcing catkin_ws it works ok for me:

Hi @albertoezquerro ,

Thanks, your solution worked with a small change.

I tried catkin_make && source devel/setup.bash yesterday as well as today, it did not work the first time.

I deleted build and devel directories within catkin_ws and ran catkin_make && source devel/setup.bash again. This time it worked. I have no idea what went wrong but everything works fine now!

As a precaution for the future, I will first do the above two steps on every course when I start or continue from the units.

Thanks again,
Girish

1 Like