0

ラズベリーパイ用に設計されたGPSユニットの1つにadafruitが提供するサンプルスクリプトを実装しようとしています。コードは次のとおりです。

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

    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

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

4

1 に答える 1

5

スクリプトの名前を gps.py 以外に変更してみてください。Python インタープリターは、システム ライブラリのどこかにある gps.py スクリプトではなく、それをインポートしようとしています。

于 2013-03-01T22:03:09.590 に答える