Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python GPSD Library Import Configuration

I'm working on a writing a Python script that will interface with and pull GPSD data into an application. This obviously involves an external library.

I have set up my configuration as follows on the Raspberry Pi I am using to deploy the code:

sudo apt-get install gpsd gpsd-clients python-gps

I have a working test sample code that creates the gps listener and pulls in data. It looks something like this:

gpsd = gps(mode=WATCH_ENABLE)
while gpsp.running:
    gpsd.next()

It works great if I run it by calling the following command:

python test.py

But the code breaks due to an ImportError:

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    from gps import *
ImportError: No module named gps

If I run it using:

python3 test.py

This makes sense to me because when I set up the project, I only included the libraries for the default Python (Python 2.7), not Python 3. But python3-gps isn't a package, and the rest of my project demands Python 3, so I don't know what to do.

Would it be possible to copy the Python 2.7 build of the gps library into Python 3 without errors? What other libraries should I look at? Is there anyway around this error?

Thanks so much!

like image 301
James Taylor Avatar asked Sep 27 '26 10:09

James Taylor


2 Answers

There actually is a version make for version 3 -- see GitHub here...

https://github.com/tpoche/gps-python3

It advertises itself as a simple port to python 3....

like image 63
Henry Crutcher Avatar answered Sep 29 '26 22:09

Henry Crutcher


The GPS3 project found on github is Python 2.7 to 3.4 compatible interface to the gpsd, yet doesn't import ancient cruft.

It is still alpha, but I would recommend it, at least for a poke and prod.

like image 36
Nodak Avatar answered Sep 30 '26 00:09

Nodak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!