user28915
user28915

Reputation: 1

GPS Daemon on Raspberry Pi

I'm trying to implement a sample script that adafruit provides for one of their gps units designed for raspberry pi. The code is as follows:

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

    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"

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

So I add "#!/usr/bin/python -tt" to the top of a "gps.py" file and then "chmod u+x /home/pi/gps.py"

Upon running this, though, I get the following error and I don't understand why:

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

    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

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

Upvotes: 0

Views: 2599

Answers (1)

user206545
user206545

Reputation:

Try renaming your script to something other than gps.py. The python interpreter is trying to import it rather that the gps.py script that is located in a system library somewhere.

Upvotes: 5

Related Questions