[英]@!/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]: [注意]:
chmod +x mypythonscript.py
) chmod +x mypythonscript.py
) #!/usr/bin/python3
or #!/usr/bin/env python3
) instead. #!/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.