简体   繁体   English

安装后,Python + RaspberryPI无法导入GPIO:ImportError:没有名为_GPIO的模块

[英]Python + RaspberryPI can't import GPIO after installing: ImportError: No module named _GPIO

I have a RPi 2 (running raspbian jessie with pixel) and just tried to install the GPIO module: 我有一个RPi 2(运行带有像素的raspbian jessie),只是尝试安装GPIO模块:

I have downloaded and installed from source. 我已经从源代码下载并安装了。 Then I issue commands: 然后我发出命令:

pi@raspberry:python
>>> import RPi.GPIO as GPIO
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
ImportError: No module named _GPIO

so then I tried using sudo: 所以我尝试使用sudo:

pi@raspberry:sudo python
>>> import RPi.GPIO as GPIO
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
ImportError: No module named _GPIO

Then I removed the module from python, and installed it again using pip: 然后我从python中删除了该模块,然后使用pip再次安装了该模块:

pi@raspberry:sudo pip install RPi.GPIO
pi@raspberry:sudo python
>>> import RPi.GPIO as GPIO
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
ImportError: No module named _GPIO

Then I removed the module from python, and installed it again using apt-get: 然后我从python中删除了模块,并使用apt-get再次安装了该模块:

pi@raspberry:sudo apt-get update
pi@raspberry:sudo apt-get -y install python-rpi.gpio
pi@raspberry:sudo python
>>> import RPi.GPIO as GPIO
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
ImportError: No module named _GPIO

It seems it has nothing to do with the install method, so I'm assuming it's something to do with either Raspbian Jessie + pixel or the current version of python-gpio is broken/incompatible. 似乎与install方法无关,所以我假设这与Raspbian Jessie + pixel或当前版本的python-gpio损坏/不兼容有关。

Its strange because I am not importing "_GPIO", I am importing "GPIO", which indicates to me that my python syntax is not the culprit. 这很奇怪,因为我没有导入“ _GPIO”,而是导入了“ GPIO”,这向我表明我的python语法不是罪魁祸首。

Could somebody please recommend what I should try next? 有人可以建议我下一步应该尝试什么吗?

Also I searched this exact error on Google and got 1 result which was not helpful. 另外,我在Google上搜索了此确切错误 ,并得到1个结果,这没有帮助。

Thanks, 谢谢,

我认为您在当前目录中有一个名为RPi的目录,因此将您的python文件更改为另一个没有的目录,它对我有用...希望有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM