I have Ubuntu Core installed on a Raspberry Pi 3.

The purpose is to use the Pi as the brains of a robotic system I am building so executing Python code which interacts with the Pis' pins through GPIO is essential.

Executing my python script results in the following error message:

Traceback (most recent call last):
  File "motors.py", line 3, in <module>
    import RPi.GPIO as gpio
ImportError: No module named RPi.GPIO

So I looked for a resource to guide me in installing RPi.GRIO. But when I try I get the following message:

sudo apt-get install python-rpi.gpio python3-rpi.gpio -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python-rpi.gpio
E: Couldn't find any package by glob 'python-rpi.gpio'
E: Couldn't find any package by regex 'python-rpi.gpio'
E: Unable to locate package python3-rpi.gpio
E: Couldn't find any package by glob 'python3-rpi.gpio'
E: Couldn't find any package by regex 'python3-rpi.gpio'

That should work for Raspbian but it seems to me Ubuntu Core might not have a python GPIO package - I hope I'm wrong.

Can anyone help, please? I desperately need to interface with GPIO or all my hard work is for nought.


I tried this but received the following error message:

sudo apt-get install python-pip python-dev python3-dev -y
sudo pip install RPI.GPIO

Traceback (most recent call last):
  File "/usr/bin/pip", line 11, in <module>
  File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 215, in main
    locale.setlocale(locale.LC_ALL, '')
  File "/usr/lib/python2.7/locale.py", line 581, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting
  • why do you need to run Ubuntu?
    – jsotola
    Mar 20, 2018 at 1:21
  • 1
    have you seen this? askubuntu.com/questions/621134/gpio-on-raspberry-pi
    – jsotola
    Mar 20, 2018 at 7:35
  • 1
    @jsotola: I updated my post with feedback. And I'm running ubuntu because it's the only OS that supports ROS - as far as I know
    – sisko
    Mar 20, 2018 at 8:47
  • @jsotola: Your suggestion worked, with some adjustments. If you want to provide an answer, I will accept it
    – sisko
    Mar 20, 2018 at 9:50
  • ROS can be installed on Raspbian but it looks quite involved (I should also note that link talks about Raspbian Jessie which is rather out of date now). I'm quite surprised pip is broken on Ubuntu Core, but then Core isn't "normal" Ubuntu - you may want to try Ubuntu MATE which is much closer to "normal" Ubuntu.
    – Dave Jones
    Mar 20, 2018 at 10:13

3 Answers 3


this is reprint of an answer by karel at this location https://askubuntu.com/questions/621134/gpio-on-raspberry-pi

In the terminal type:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-pip python-dev
sudo pip install RPi.GPIO  

The raspberry-gpio-python examples are worth reading. In the Inputs example there is this code snippet:

while GPIO.input(channel) == GPIO.LOW:

It waits 10 ms to give CPU a chance to do other things.

  • youll get this error: ``` Traceback (most recent call last): File "relay_board.py", line 10, in <module> GPIO.setup(20, GPIO.OUT, initial=GPIO.LOW) RuntimeError: Not running on a RPi! ``` Editing your LC_ALL environment variable does not work Running with sudo permissions works for me
    – Airfield20
    Jan 8, 2020 at 17:29

It is because your environment variable LC_ALL is missing or invalid somehow. just run
$ export LC_ALL=C


You can just install the GPIO library for Python3 using the command

sudo apt-get install python3-rpi.gpio

It worked for me for Ubuntu 20.04 and 22.04

After that, you can follow the steps for using the GPIO library here sparkfun- raspberry pi gpio

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.