Using GPS library in Python 3

11,284

That project is a warts and all port of the python-gps package to Python 3.

The python-gps files live at /usr/lib/python2.7/dist-packages/gps/

You can put gps-python3 files in your Python 3 path by creating and placing them in an analogous directory, e.g., /usr/local/lib/python3.4/dist-packages/gps/ The module will then be available as it would in Python2. There is no installer

Another option is use gps3.py. It's still alpha, but is a fresh python client for the gpsd. It works with any Python from 2.7 to 3.4. It can be either placed in a directory such as /usr/local/lib/python3.4/dist-packages/gps/, placed in the directory of your python script, or executed directly via python3 /path/to/gps3.py

Your python script is easy to adapt as it uses the same name(s) as the json stream from the gpsd.

from gps3 import gps3
the_connection = gps3.GPSDSocket() 
the_fix = gps3.Fix()
try:
    for new_data in the_connection:
        if new_data:
            the_fix.refresh(new_data)
        if not isinstance(the_fix.TPV['lat'], str): # lat as determinate of when data is 'valid'
            speed = the_fix.TPV['speed']
            latitude = the_fix.TPV['lat']
            longitude = the_fix.TPV['lon']
            altitude  = the_fix.TPV['alt']
            # etc....
Share:
11,284
srinivas
Author by

srinivas

Updated on June 04, 2022

Comments

  • srinivas
    srinivas about 2 years

    I want to use GPS library in Python 3. I came across this on https://github.com/tpoche/gps-python3

    How do I 'install' these files? Should I simple copy them to my folder? Or is there any way of installing them?