如何使用/安装GPS Python库

5 投票
2 回答
11155 浏览
提问于 2025-04-17 18:37
root@raspberrypi:~# python
Python 2.7.3 (default, Jan 13 2013, 11:20:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from gps import gps
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name gps
>>> exit ()

这似乎不太好使。
我安装了这些Debian软件包:
gpsd、gpsd-clients、python-gps、libgps20、libgps-dev

2 个回答

1

可能有必要补充一下,即使在删除了gps.py文件后,我还有一个叫做gps.pyc的文件,这个文件也在造成这个问题。只要把这个文件删除,问题就会消失。

3

我在一台Ubuntu机器上试过,效果很好:

$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from gps import gps
>>>

首先,确保以下文件存在(保存的目录可能会因为不同而不同):

/usr/lib/pyshared/python2.7/gps/packet.so
/usr/lib/pyshared/python2.7/gps/clienthelpers.so
/usr/lib/python2.7/dist-packages/gps-3.6.egg-info
/usr/lib/python2.7/dist-packages/gps/misc.py
/usr/lib/python2.7/dist-packages/gps/client.py
/usr/lib/python2.7/dist-packages/gps/fake.py
/usr/lib/python2.7/dist-packages/gps/__init__.py
/usr/lib/python2.7/dist-packages/gps/gps.py

你可以通过运行以下命令来检查:

dpkg -L python-gps

另外,确保在你运行Python的目录里没有叫gps.py的文件,因为这可能会搞乱导入的过程。

撰写回答