2

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!

James Taylor
  • 6,158
  • 8
  • 48
  • 74

3 Answers3

2

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....

Henry Crutcher
  • 2,137
  • 20
  • 28
  • Thanks for the reply! How do you "install" it? I have no idea which directory to copy the build over to or how to get it working properly. – James Taylor Feb 06 '15 at 05:07
  • I would (assuming you don't want to mess with virtualenvs) either install it in a subdir of your home directory or your project and add that subdir to your PYTHONPATH or install it in the source directory you are writing your project in. – Henry Crutcher Feb 06 '15 at 05:40
  • Yeah I tried just putting it in my current working forlder, but I keep getting `TypeError: 'module' object is not callable`. Any ideas on how to get around this? – James Taylor Feb 06 '15 at 05:51
  • Yep -- my guess is that the extra gps directory means you need to do a from gps.gps import GPSData – Henry Crutcher Feb 06 '15 at 13:32
2

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.

Nodak
  • 929
  • 1
  • 8
  • 14
  • @JamesTaylor ...but to answer your python2.7 import problem it's really `from gps import gps` or you could give gps3 a whirl. – Nodak Feb 11 '15 at 05:21
1

If you have pip3 installed use

pip3 install gps
laudarch
  • 573
  • 5
  • 7