树莓派上的GPS守护进程
我正在尝试实现一个Adafruit为他们的一款适用于树莓派的GPS设备提供的示例脚本。代码如下:
==============
import gps
# Listen on port 2947 (gpsd) of localhost
session = gps.gps("localhost", "2947")
session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
while True:
try:
report = session.next()
# Wait for a 'TPV' report and display the current time
# To see all report data, uncomment the line below
# print report
if report['class'] == 'TPV':
if hasattr(report, 'time'):
print report.time
except KeyError:
pass
except KeyboardInterrupt:
quit()
except StopIteration:
session = None
print "GPSD has terminated"
==============
所以我在“gps.py”文件的顶部添加了“#!/usr/bin/python -tt”,然后运行了“chmod u+x /home/pi/gps.py”来给这个文件添加执行权限。
但是,当我运行这个文件时,我遇到了以下错误,我不明白为什么会这样:
==============
pi@raspberrypi ~ $ /home/pi/gps.py
Traceback (most recent call last):
File "/home/pi/gps.py", line 2, in <module>
import gps
File "/home/pi/gps.py", line 5, in <module>
session = gps.gps("localhost", "2947")
TypeError: 'module' object is not callable
==============
1 个回答
5
试着把你的脚本改个名字,不要叫 gps.py。因为 Python 解释器在尝试导入你这个文件,而不是系统库里那个真正的 gps.py 脚本。