env: python\r: No such file or directory error : even though there is no /r/n in the script

env: python\r: No such file or directory error : even though there is no /r/n in the script

我正在 Ubuntu 20.04 Raspberry Pi

我读到这个错误是由 Windows - Unix 格式冲突引起的 但是我的脚本里面没有/r/n,我该如何解决呢?

#!/usr/bin/env python

import rospy
from laser_assembler.srv import *
from sensor_msgs.msg import PointCloud2

rospy.init_node("test_client") 
rospy.wait_for_service("assemble_scans2")
assemble_scans = rospy.ServiceProxy('assemble_scans2',AssembleScans2)
pub = rospy.Publisher("/pointcloud", PointCloud2, queue_size = 1)
r = rospy.Rate(1)

while not rospy.is_shutdown():
    try:
        resp = assemble_scans(rospy.Time(0,0), rospy.get_rostime())
        print "Got cloud with %u points" % len(resp.cloud.data)
        pub.publish(resp.cloud)

    except rospy.ServiceException, e:
        print "Service call failed: %s" %e
        
    r.sleep()

Windows 默认使用 CRLF 行结尾,而 Linux/Unix 使用 LF 行结尾。 如果您的应用程序同时使用 windows 和 linux,最好将您的代码保留在 LF 中,因为这两个平台都理解 LF 行尾。

将代码转换为 unix 兼容行尾的一种简单方法是使用 Vi/Vim 并将行尾显式设置为 LF。

在 Vi 中使用此命令 - :set ff=unix 将行尾设置为 LF。然后您的代码应该可以工作了。

为了避免进一步的冲突,在 Windows 上进行开发时,请务必检查您的文本编辑器行尾设置是否设置为 LF。