【发布时间】:2015-05-07 01:53:12
【问题描述】:
我想在 Python 3 中使用 GPS 库。我在 https://github.com/tpoche/gps-python3 遇到了这个
如何“安装”这些文件?我应该简单地将它们复制到我的文件夹吗?或者有什么方法可以安装它们?
【问题讨论】:
标签: python-3.x gps gpsd
我想在 Python 3 中使用 GPS 库。我在 https://github.com/tpoche/gps-python3 遇到了这个
如何“安装”这些文件?我应该简单地将它们复制到我的文件夹吗?或者有什么方法可以安装它们?
【问题讨论】:
标签: python-3.x gps gpsd
该项目是一个缺点,并且将 python-gps 包的所有端口都移植到 Python 3。
python-gps 文件位于/usr/lib/python2.7/dist-packages/gps/
您可以将 gps-python3 文件放入您的 Python 3 路径中,方法是创建并将它们放置在类似的目录中,例如 /usr/local/lib/python3.4/dist-packages/gps/ 该模块将像在 Python2 中一样可用。没有安装程序
另一个选项是使用gps3.py。它仍然是 alpha,但它是 gpsd 的全新 python 客户端。它适用于从 2.7 到 3.4 的任何 Python。可以放在/usr/local/lib/python3.4/dist-packages/gps/等目录下,也可以放在你的python脚本目录下,也可以直接通过python3 /path/to/gps3.py执行
您的 python 脚本很容易适应,因为它使用与来自 gpsd 的 json 流相同的名称。
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....
【讨论】:
sudo mkdir /usr/local/lib/python3.2/dist-packages/gps/ 然后sudo cp 随便什么