GPS Python模块E

2024-10-01 09:41:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在rpi上使用this script。如果gpsd正在运行,并且我从链接的博客文章运行脚本,则会出现以下错误:

  File "/home/zzz/Timelapse/staticgps.py", line 29, in <module>
    gpsp = GpsPoller() # create the thread
  File "/home/zzz/Timelapse/staticgps.py", line 19, in __init__
    gpsd = gps.gps(mode=WATCH_ENABLE) #starting the stream of info
NameError: global name 'gps' is not defined

知道出什么事了吗?谢谢!!在

编辑:这是我按要求写的剧本。它是从链接直接复制/粘贴。在

^{pr2}$

Tags: theinpyhome链接linescriptthis
3条回答

您没有正确复制代码;链接页面有以下行:

gpsd = gps(mode=WATCH_ENABLE) #starting the stream of info

注意,它只是gps(),而不是gps.gps();在脚本的顶部,gps模块的所有名称都导入到当前名称空间中,使gps()成为本地名称。在

确保do将语句from gps import *放在脚本的顶部,从错误消息中可以看出您没有正确导入它(NameError表示脚本中没有导入名为gps任何内容)。在

将WATCH_ENABLE替换为1,它可以工作。 我不知道为什么这个常量不公开(newbie)-它是在中声明的客户端.pygps模块的

如果有人在这里遇到同样的问题,那是因为您的脚本文件名为gps.py. 只需将其重命名为其他名称,导入将正常工作。在

相关问题 更多 >