简体   繁体   English

@!/usr/bin/env: 当我尝试使用 ros 节点时没有这样的文件或目录

[英]@!/usr/bin/env: No such file or directory when i try to use ros nodes

I tried to write a subscriber and publisher node;我试着写一个订阅者和发布者节点; but when I try to run the publisher with rosrun , it gives me an error: @!/usr/bin/env: No such file or directory但是当我尝试使用rosrun运行发布rosrun ,它给了我一个错误: @!/usr/bin/env: No such file or directory

Here is the error and the corresponding code (I did chmod +x ):这是错误和相应的代码(我做了chmod +x ):

Publisher node:发布者节点:

@!/usr/bin/env python

import rospy
from std_msgs.msg import String

def publish_it():
    pub = rospy.Publisher("first_msgs",String , queue_size = 10)
    rospy.init_node("publisher_node",anonymous = True)
    x = 1
    z = 10
    rate = rospy.Rate(z) #1/z sec delay

    while not rospy.is_shutdown():
        x += 1
        if x == 100:
            x = 0

        msg = "Hi this is our first message . times:" + str(x)
        rospy.loginfo(msg)
        pub.publish(msg)
        rate.sleep()

if __name__ == "__main__":
    try:
        publish_it()
    except rospy.ROSInterruptException:
        pass

Subscriber node:订阅者节点:

@!/usr/bin/env python

import rospy
from std_msgs.msg import String

def callback(data):
    rospy.loginfo(data.data)

def iSeeIt():
    rospy.init_node("subscriber_node",anonymous = True)
    rospy.Subscriber("first_msgs",String,callback)
    rospy.spin()

if __name__ == "__main__":
    iSeeIt()

You are misusing the shebang construct. 您正在滥用shebang构造。 Instead of using @! 而不是使用@! you have to write #! 你必须写#! , followed by the interpreter which should be applied to your code. ,然后是应应用于您的代码的解释器。 Furthermore, the line (ie #!/usr/bin/env python ) needs to be in the first row of your script. 此外,该行(即#!/usr/bin/env python )需要位于脚本的第一行。 Thus, the head of your subscriber node should look like this: 因此,您的订户节点的头应如下所示:

#!/usr/bin/env python
# subscriber node

import rospy
from std_msgs.msg import String
...

rospy init must be placed before the publisher, and your code shebang should be as the following: rospy init必须放在发布者之前,并且您的代码shebang应该如下所示:

#!/usr/bin/env python

import rospy
from std_msgs.msg import String

def publish_it():
    rospy.init_node("publisher_node", anonymous=True)
    pub = rospy.Publisher("first_msgs", String, queue_size=10)
    x = 1
    z = 10
    rate = rospy.Rate(z)
    ....

[NOTE]: [注意]:

  • Make sure the Python script is executable ( chmod +x mypythonscript.py ) 确保Python脚本是可执行的( chmod +x mypythonscript.py
  • If you are using Python3 in ROS using this shebang ( #!/usr/bin/python3 or #!/usr/bin/env python3 ) instead. 如果您在ROS中使用Python3 ,请使用此shebang( #!/usr/bin/python3#!/usr/bin/env python3 )。

Thank you guys, i solved it by changing @!/usr/bin/env python with #!/usr/bin/python2.7 . 谢谢大家,我通过使用#!/ usr / bin / python2.7更改@!/ usr / bin / env python来解决了这个问题。 I am using python3 and i don't really understand how it works but i works 我正在使用python3,但我不太了解它是如何工作的,但是我可以工作

sudo apt-get install python-is-python3须藤 apt-get 安装 python-is-python3

write this code it will be solve your problem编写此代码将解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ubuntu /usr/bin/env: python: 没有那个文件或目录 - ubuntu /usr/bin/env: python: No such file or directory /usr/bin/env: python,没有那个文件或目录 - /usr/bin/env: python, No such file or directory hadoop /usr/bin/env: python: 没有那个文件或目录 - hadoop /usr/bin/env: python: No such file or directory WSL: /usr/bin/env: 'python': 没有那个文件或目录 - WSL: /usr/bin/env: ‘python’: No such file or directory /usr/bin/env: python3: 从 cron 运行脚本时没有这样的文件或目录 - /usr/bin/env: python3: No such file or directory when running script from cron Ansible Playbook 在通过 Jenkins 执行时失败:/usr/bin/env: 'python3': No such file or directory - Ansible Playbook Fails when Executed Through Jenkins: /usr/bin/env: ‘python3’: No such file or directory / usr / bin / env:python2.6:没有这样的文件或目录错误 - /usr/bin/env: python2.6: No such file or directory error zsh:没有这样的文件或目录:#!/ usr / bin / env python3 - zsh: no such file or directory: #!/usr/bin/env python3 运行 poetry 失败并显示 /usr/bin/env: 'python': No such file or directory - Running poetry fails with /usr/bin/env: ‘python’: No such file or directory Windows 10:/usr/bin/env:'python3':没有那个文件或目录 - Windows 10: /usr/bin/env: ‘python3’: No such file or directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM