How to Solve NameError: name 'rospy' is not defined

Solution: Import the 'rospy' module

To Solve the error, add the following line to the top of your code.

import rospy

 

For more information:
Python rospy