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
答案 0 :(得分: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
,因为这可能会导致导入程序失败。
答案 1 :(得分:1)
即使在删除gps.py之后添加它也可能很有用,我有一个名为gps.pyc的文件,它也创建了这个问题。你删除这个文件,然后问题消失..