Raspberry Pi上的GPS守护进程

时间:2013-03-01 18:15:37

标签: python gps raspberry-pi

我正在尝试实现adafruit为其中一个为覆盆子pi设计的gps单元提供的示例脚本。代码如下:

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

    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”添加到“gps.py”文件的顶部,然后“chmod u + x /home/pi/gps.py”

运行时,我收到以下错误,我不明白为什么:

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

    pi@raspberrypi ~ $ /home/pi/gps.py
    Traceback (most recent call last):
      File "/home/pi/gps.py", line 2, in <module>
        import gps
      File "/home/pi/gps.py", line 5, in <module>
        session = gps.gps("localhost", "2947")
    TypeError: 'module' object is not callable

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

1 个答案:

答案 0 :(得分:5)

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