【问题标题】:Using GPS library in Python 3在 Python 3 中使用 GPS 库
【发布时间】:2015-05-07 01:53:12
【问题描述】:

我想在 Python 3 中使用 GPS 库。我在 https://github.com/tpoche/gps-python3 遇到了这个

如何“安装”这些文件?我应该简单地将它们复制到我的文件夹吗?或者有什么方法可以安装它们?

【问题讨论】:

    标签: python-3.x gps gpsd


    【解决方案1】:

    该项目是一个缺点,并且将 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....
    

    【讨论】:

    • 我尝试将它们放在目录 /usr/local/lib/python3.2/dist-packages 但我收到一条错误消息说 gps: Error Creating directory: Permission denied 我正在这样做树莓派。有没有办法解决这个问题?
    • sudo mkdir /usr/local/lib/python3.2/dist-packages/gps/ 然后sudo cp 随便什么
    猜你喜欢
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 2023-01-16
    • 2014-10-13
    • 2011-11-12
    • 2019-12-29
    • 2014-07-21
    • 2018-10-22
    相关资源
    最近更新 更多