Raspberry Pi上的GPS守护程序

2024-05-13 23:23:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试实现一个示例脚本,adafruit为他们的一个gps单元设计的树莓pi。代码如下:

=============

    import gps

    # Listen on port 2947 (gpsd) of localhost
    session = gps.gps("localhost", "2947")
    session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)

    while True:
        try:
            report = session.next()
            # Wait for a 'TPV' report and display the current time
            # To see all report data, uncomment the line below
            # print report
            if report['class'] == 'TPV':
        if hasattr(report, 'time'):
            print report.time
        except KeyError:
            pass
        except keyboardInterrupt:
            quit()
        except StopIteration:
            session = None
            print "GPSD has terminated"

=============

所以我加上“#”!/usr/bin/python-tt“到a的顶部”gps.py“文件,然后”chmod u+x/home/pi/gps.py““

但是,在运行此程序时,我得到了以下错误,我不明白为什么:

=============

^{pr2}$

=============


Tags: thepyreport脚本localhost示例iftime
1条回答
网友
1楼 · 发布于 2024-05-13 23:23:11

尝试将脚本重命名为gps.py. python解释器试图导入它而不是gps.py位于某个系统库中的脚本。在

相关问题 更多 >