Ah, I looked up other users who reported something similar and it turned out I shouldn’t have chosen the Raspberry Pi3 64-bit. Using the default one works. Newbie mistake here
Hello there,
I am trying to use the RPi.GPIO to enable a LED on my board. I have added the RUN pip3 install smbus2 paho-mqtt requests RPi.GPIO
But when I add in my code import RPi.GPIO as GPIO it returns
sensor File "/usr/lib/python3/dist-packages/RPi/GPIO/__init__.py", line 23, in <module>
sensor from RPi._GPIO import *
sensor ModuleNotFoundError: No module named 'RPi._GPIO'
You are using the 32 bit OS, as indicated above, correct?
Assuming that you are using the correct OS, it seems to me that the issue you see is in your build. I don’t normally program in Python, but the message would seem to indicate that it’s not really a there is something going on with the package manager and/or Python version.
I found two links that seem to talk about this. Do either of these help?
Hello @toochevere
I am using the balenaOS 2.71.3+rev5. I really don’t know if its the 32 bit OS, although when I build it repos the aarch64. I have done both the links above and still it can not go through the import RPi.GPIO as GPIO. Smbus works ok and its i2c!!!
Hi @gmav, what device are you using? Raspberry Pi 3 or 4? You can check if your OS is 32 or 64 bits by visiting the device page on the balenaCloud dashboard. If it says Raspberry Pi 4 or Raspberry Pi 3-64 then its 64bits, otherwise it’s 32.
Also, can you provide the full Dockerfile.template file?
Hey, I found that for whatever reason installing RPI.GPIO from apt-get (which is what install_packages does) results in the problem you are experiencing. If you remove python3-rpi.gpio and python-rpi.gpio from the install list, and then install it with pip then it works.
Hello @tmigone,
Thank you for your reply… Your suggestion did work . This is not correct to have happened. Or if its a bug in the procedure it should be mentioned somewhere. Thank you again for the help.
Hello again @tmigone,
Since this morning, and although I haven’t changed my requirement list, it stopped working. Is there something done and I can not once more have a simple GPIO library to work with? This is the message I get when I try to build and upload:
[sensor] ERROR: Command errored out with exit status 1: /usr/local/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-lne8jb3i/rpi-gpio_9a071875ba0a4d8a905cb78ac63f7f20/setup.py'"'"'; __file__='"'"'/tmp/pip-install-lne8jb3i/rpi-gpio_9a071875ba0a4d8a905cb78ac63f7f20/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-4nikewxl/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.9/RPi.Gpio Check the logs for full command output.
any update to this? I have encountered the same problem. 64-bit. Not sure what base image to use but same as here Aarch64 on a RPi4B. How do we call GPIO?