LED Alerter code fails to push to app

Tried pushing the LED alerter code to my app a few times. I keep seeing this:

[main]     E: Unable to locate package rpi.gpio
[main]     E: Couldn't find any package by glob 'rpi.gpio'
[main]     E: Couldn't find any package by regex 'rpi.gpio'
[main]     E: Unable to locate package python-rpi.gpio
[main]     E: Couldn't find any package by glob 'python-rpi.gpio'
[main]     E: Couldn't find any package by regex 'python-rpi.gpio'
[main]
[main]     Removing intermediate container <redacted>
[main]     The command '/bin/sh -c apt-get update && apt-get install -yq --no-install-recommends              rpi.gpio   python-dev   python-rpi.gpio   && apt-get clean && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 100
[Info]     Uploading images
[Success]  Successfully uploaded images
[Error]    Some services failed to build:
[Error]      Service: main
[Error]        Error: The command '/bin/sh -c apt-get update && apt-get install -yq --no-install-recommends   rpi.gpio   python-dev   python-rpi.gpio   && apt-get clean && rm -rf /var/lib/apt/lists/*' returned a non-zero code: 100
[Info]     Built on arm01
[Error]    Not deploying release.

Trying to build on Raspberry Pi3B+, on Windows 10.

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 :slight_smile:

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'

Have you solved this?

Hello @gmav. Thanks for your question.

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?

https://www.raspberrypi.org/forums/viewtopic.php?t=275387

Please confirm that you are using the 32 bit OS and let us know if either of those links gets you unstuck.

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?

Hi @tmigone,
I am using a Raspberry Pi CM4 IO Board. The Arch is aarch64. The Dockerfile.template is:

FROM balenalib/%%BALENA_ARCH%%-debian-python

WORKDIR /usr/src/app

ENV INITSYSTEM on

RUN /usr/local/bin/python3.9 -m pip install --upgrade pip

RUN install_packages \

    nano \

    i2c-tools \

    kmod \

    libiio0 \

    libiio-utils \

    python3-libiio \

    python3-rpi.gpio \

    python-rpi.gpio \

    git \

    python3-dev \

    python-dev

RUN apt-get update -y && apt-get install build-essential

COPY ./requirements.txt /requirements.txt

RUN pip install -r /requirements.txt

# COPY . /usr/src/app

# WORKDIR /usr/src/app

COPY *.py ./

COPY *.c ./

COPY *.json ./

ENV UDEV=on


CMD ["python3", "test_mk00.py"]

and the requirements.txt is:

smbus2
paho-mqtt
requests
RPi.Gpio

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.

1 Like

Hello @tmigone,
Thank you for your reply… Your suggestion did work :slight_smile: . 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.

Hey, @gmav can you share your Dockerfile in here please?