Adding python modules within BalenaOS on RPi4

Hello there!

I get the error message below when I try to push my code to my RPi4 running the balenaOS.

I’m assuming it’s because the python on balenaOS doesn’t have the module I need (RPi.GPIO), so my question is how do I install / add python modules on it?

Kind regards,


You should install the module in your Dockerfile and as you’re using Python so I assume pip is installed. Can you please add something like RUN pip install RPi.GPIO to you Dockerfile and try again?

Hey, thanks for the reply!

I’ve tried to change the dockerfile but I’m still getting an error when I try to push code on the Pi. I tried to push RPi.GPIO by itself but pip requires gcc, so I tried to push both gcc and RPi.GPIO and gcc installs fine, however it still doesn’t recognize the gcc command when trying to pip install RPi.GPIO. Is there perhaps a solution around this?

Here’s the error message when trying to push with balena:

And here is my docker file:


I managed to get balena to push everything by switching from gcc to build-essential!

Now the issue is the logs still show that RPi.GPIO can’t be imported because it doesn’t exist. Also I can’t seem to find python anywhere using the host OS terminal.

Update 2

Everything works! I didn’t realize python defaulted to the same folder the project was in where I had some leftover RPi modules, so once I deleted them it worked out clean.

Thanks again, I didn’t even know what docker files were before your reply!

Glad you sorted it out :slight_smile: