ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Cannot run node with rosrun but only python

asked 2020-09-25 09:42:54 -0500

Ariel gravatar image


I have an arm based system, with ubuntu 18.04 running melodic. I have a sample code to run a node that only publishes an array defied in a custom message:

 import rospy
from dma.msg import dma_data

def dma_loop():
    pub = rospy.Publisher('DMA_output', dma_data, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(2) # 10hz
    vec = dma_data()
    num = 0
    while not rospy.is_shutdown():
        #hello_str = "hello world %s" % rospy.get_time()
        num = num + 1
        if num>251:
        vec.array = [num, num, num, num, num]
        #for i in range(5):
        #    vec.array[i] = num

if __name__ == '__main__':
    except rospy.ROSInterruptException:

After running catkin_make and sourcing devel/setup.bash if I run rosrun, I get:

xilinx@pynq:~$ rosrun dma 
/home/xilinx/catkin_ws/src/dma/scripts/ line 1: import: command not found
from: can't read /var/mail/dma.msg
/home/xilinx/catkin_ws/src/dma/scripts/ line 4: syntax error near unexpected token `('
/home/xilinx/catkin_ws/src/dma/scripts/ line 4: `def dma_loop():'

However, if I execute it directly with python it works and I can echo the topic that it publishes. Is there something else to do?

Thank you.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-09-25 10:47:08 -0500

gvdhoorn gravatar image

It's very likely your script is not executable.

It also doesn't have a shebang.

Run chmod +x and add #!/usr/bin/env python as the shebang.

edit flag offensive delete link more


And note: this is not ROS specific.

gvdhoorn gravatar image gvdhoorn  ( 2020-09-25 10:47:59 -0500 )edit

I missed the #!/usr/bin/env python. Thanks for the answer.

Ariel gravatar image Ariel  ( 2020-09-25 10:51:33 -0500 )edit

I don't know if I should open a new thread for this.... I want to include in the same python code that only works with sudo python3.6 That would not work here, right?

Ariel gravatar image Ariel  ( 2020-09-25 10:53:28 -0500 )edit

Please search for older Q&As around this topic (use Google: append to your query).

The answer is not using sudo.

Give the user that starts the node access to the resource instead.

gvdhoorn gravatar image gvdhoorn  ( 2020-09-25 10:54:44 -0500 )edit

sudo could be circumvented if I understood what you mean by "Give the user that starts the node access to the resource instead.". But what about python3.6?

Ariel gravatar image Ariel  ( 2020-09-25 11:00:44 -0500 )edit

Question Tools

1 follower


Asked: 2020-09-25 09:42:54 -0500

Seen: 1,528 times

Last updated: Sep 25 '20