2

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.

UPDATE:

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>
    sys.exit(main())
  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
sisko
  • 287
  • 2
  • 4
  • 9

3 Answers3

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:
    time.sleep(0.01)

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

jsotola
  • 705
  • 1
  • 9
  • 13
0

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

0

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