Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: No module named _GPIO #1

Open
janhenrikbern opened this issue Apr 18, 2018 · 10 comments
Open

ImportError: No module named _GPIO #1

janhenrikbern opened this issue Apr 18, 2018 · 10 comments

Comments

@janhenrikbern
Copy link

Hi emutex,

I built RPi.GPIO from your repository and followed INSTALL.TXT on my Intel UP board. When I tried to import RPi.GPIO, python (2.7) returns:

"""
File "RPi/GPIO/init.py", line 23, in
from RPi._GPIO import *
ImportError: No module named _GPIO
"""

Please let me know if there is something else I need to look out for during the installation process.

Thank you!

@jennyshane
Copy link

I am having the same problem. I have a regular upboard running ubuntu 16.04. I followed the instruction here: https://wiki.up-community.org/Ubuntu to install ubuntu.

@jennyshane
Copy link

I solved this by changing the line "from RPi._GPIO import *" in RPi/GPIO/init.py to "from .._GPIO import *"

@ghost
Copy link

ghost commented Jun 4, 2019

@jennyshane had the correct idea. A simple update of __init__.py in RPi/GPIO/ solves the issue by replacing from RPi._GPIO import * with from RPi.GPIO import *

Tested on Python 3.7.2 - Raspberry Pi Debian

@builder555
Copy link

I've had the same issue, the problem was that i was installing rpi.gpio using apt-get install python-rpi.gpio, problem went away when i did this:

apt-get install build-essential
pip install RPi.Gpio

trying to install RPi.Gpio without build-essential throws error that it's missing gcc.

@xoxota99
Copy link

xoxota99 commented Sep 17, 2021

Still not working (on Ubuntu 20.04 for RPi). I've tried all the suggestions here, and still get:
Traceback (most recent call last): File "blinker.py", line 2, in <module> import RPi.GPIO as GPIO File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 23, in <module> from RPi._GPIO import * ModuleNotFoundError: No module named 'RPi._GPIO'

@etothex23
Copy link

Manjaro arm new: installed rpi-gpio and gpiozero with pacman but it installs rpi-gpio into an empty python3.8 folder, gpiozero installs into python3.9. The contents of the rpi-gpio is just init.py and a few other files. Init.py imports from _GPIO which does not exist. I think there is an install issue with Manjaro and pacman.

@cgursche
Copy link

cgursche commented Feb 9, 2022

@jennyshane had the correct idea. A simple update of __init__.py in RPi/GPIO/ solves the issue by replacing from RPi._GPIO import * with from RPi.GPIO import *

Tested on Python 3.7.2 - Raspberry Pi Debian

This gets past the module not found error (using Python3.10.2), but doesn't actually load the module (which, I'm assuming) are the .so files in the directory that start with _GPIO…)

@cgursche
Copy link

cgursche commented Feb 9, 2022

Loaded latest Raspberry Pi Debian 32 bit full onto Pi Zero clean install (Python 3.9 default)
Installed Python 3.10.2
Removed RPi*
Reinstalled RPi, latest version 0.7.1
Made sure sys.path for 3.10.2 included all paths in sys.path for 3.9
Python 3.10.2 generates the ModuleNotFoundError: No module named 'RPi._GPIO'
Python 3.9 does not
fwiw

@HallmanLabs
Copy link

In my case, where I am trying to get all of this running in a standalone copy of Jython, to call inside of Java, you need to build the RPi.GPIO package first. Using the following command in the root RPI.GPIO folder:

python3 setup.py install
(You may need to use sudo)

Once you build it, it will produce a .egg file inside of the dist file, unzip this with any normal Linux/Mac/Windows archiver and then you will have the _GPIO.py file inside of the root RPi file (inside that .egg).

Once I did that, then this all worked. Before that, I had the same issues as you all and I'm not sure just changing _GPIO to GPIO is the right fix here (at least, if you want a fully standalone copy to run this).

Note: You need to build the package on the system you intend to deploy it on, or else you'll end up with a x86 copy on your RPi (which is ARM of course).

Best of luck!

@impero78
Copy link

impero78 commented Sep 20, 2023

I have had the same issue when using the RPi.GPIO library in two identical containers one deployed on a Raspberry 1 and the other in a Raspberry 2, based on python 3.10, where the library was installed via pip install. The one in the Raspberry 2 worked fine, while the one in the Rasberry 1 did not. After a long investigation I came to the conclusion that the culprit is the precompiled RPI._GPIO, which does not load/work correctly for the Raspi 1 architecture.
In practice, RPI.GPIO tries to use the extension module RPI._GPIO (in my case ../site-packages/RPi/_GPIO.cpython-310-arm-linux-gnueabi.so) but that does not go well.
After forcing a binary recompilation, it started working as expected:

pip install --force-reinstall --no-cache-dir --no-binary :all: RPi.GPIO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants