Exercise 3.1 Can't Find geometry_msgs (python)

Hello I have been working through ROS Basics in 5 days and have run into an error on exercise 3.1. When I try and run my script it comes up with

/home/user/catkin_ws/src/robot_move_pkg/src/scripts/move_robot.py: line 4: import: command not found
from: can’t read /var/mail/geometry_msgs.msg
/home/user/catkin_ws/src/robot_move_pkg/src/scripts/move_robot.py: line 7: syntax error near unexpected token 'move'' /home/user/catkin_ws/src/robot_move_pkg/src/scripts/move_robot.py: line 7: rospy.init_node(‘move’)’

I think the error might be either with my CMakeLists.txt, package.xml or my launch file but I honestly have no idea

Any suggestions?

Hi @ThomasGaskins ,

Welcome to this Community!

As your error says that there is a “Syntax” error, we should have a look into your program.

Could you please share the python code and the terminal output as two separate code-blocks?

Refer here to know how to make a code-block: Extended Syntax | Markdown Guide


Here is my python code

#! /usr/bin/env python

import rospy
from geometry_msgs.msg import Twist

pub = rospy.Publisher('/cmd_vel', Twist, queue_size=1)
rate = rospy.Rate(2)
move = Twist()
move.linear.x = 0.5
move.angular.z = 0.5

while not rospy.is_shutdown():

and here is the output

/home/user/catkin_ws/src/robot_move_pkg/src/scripts/move_robot.py: line 4: import: command not found
from: can't read /var/mail/geometry_msgs.msg
/home/user/catkin_ws/src/robot_move_pkg/src/scripts/move_robot.py: line 7: syntax error near unexpected token `'move''
/home/user/catkin_ws/src/robot_move_pkg/src/scripts/move_robot.py: line 7: `rospy.init_node('move')'

Thanks, Thomas

Hi @ThomasGaskins ,

I believe that the problem is due to the shebang line not being the first line.
Remove the line space above #! /usr/bin/env python so that this line becomes the first line of the file.

That should solve the problem. The shebang line ALWAYS has to be the first line.
Comments and/or other stuff comes only after this line.

Let me know if you got this problem fixed.


That worked, thanks!

I thought that line had to just be the first written line, not on the first physical line of the file, thanks for correcting that

Hi @ThomasGaskins ,

Glad to know that your problem is fixed!

Please mark this issue as solved by clicking on the appropriate post as “Solution” so this issue can be closed.