6

i was trying to install rpi.gpio on raspberry pi 4 with ubuntu 20.10 desktop as follows

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-pip python-dev

it gave as

note, selecting 'python-dev-is-python2' instead of 'python-dev'
Package python-pip is not available, but is referred to by another package. 
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
  python3-pip

so i tried

    sudo apt-get install python3-pip python-dev

which installed it normally but then, for

sudo pip install RPi.GPIO 

which gives really big error as starting with

ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-00y2fso0/RPi.GPIO/setup.py'"'"'; __file__='"'"'/tmp/pip-install-00y2fso0/RPi.GPIO/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-m2w0m0n7
   cwd: /tmp/pip-install-00y2fso0/RPi.GPIO/

and ending with

 collect2: error: ld returned 1 exit status
  error: command 'aarch64-linux-gnu-gcc' failed with exit status 1
 ----------------------------------------
  ERROR: Failed building wheel for RPi.GPIO

it again ran setup as

 Running setup.py clean for RPi.GPIO
Failed to build RPi.GPIO
Installing collected packages: RPi.GPIO
Running setup.py install for RPi.GPIO ... error

failing with

error: command 'aarch64-linux-gnu-gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-00y2fso0/RPi.GPIO/setup.py'"'"'; __file__='"'"'/tmp/pip-install-00y2fso0/RPi.GPIO/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-u3ttxsed/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.8/RPi.GPIO 
Check the logs for full command output.

i found this somewhere and tried

sudo apt install rpi.gpio-common

which installed normally,please help me with this error and can I use this 'rpi.gpio-common' to control gpio pins if yes how? thanks for your time.

4
  • 1
    The package you are looking for is probably python3-rpi.gpio.
    – danzel
    Nov 6, 2020 at 11:37
  • I added that package but it give error on code execution as
    – UV0
    Nov 7, 2020 at 12:43
  • executable error: not on rpi
    – UV0
    Nov 7, 2020 at 12:43
  • One more thing there is no gpio user group on system and no drivers(code) for it how can i add it
    – UV0
    Nov 7, 2020 at 12:45

3 Answers 3

13

I was able to fix the issue by installing RPi.gpio using pip3. Type the following commands:

export CFLAGS=-fcommon

pip3 install RPi.GPIO

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

3
  • 1
    I don't know why this works but it did for me. It would be helpful if there was some additional explanation for why this works. Nov 22, 2021 at 1:09
  • 1
    As far as I am aware, the reason this works as opposed to using the apt-get install method, is due to the method in which the upstream repo built the prebuilt executable. When installing via PIP, it's building it from source, thus when you are setting the CFLAGS variable, which I believe is a GCC Variable, I Believe The reason for that is because GCC 10 defaults to -fno-common, you can see that: gcc.gnu.org/gcc-10/porting_to.html Since this was built for Arm, it may have been when they ported this they used the -fno-common flag instead of -fcommon. Nov 29, 2021 at 6:44
  • export CFLAGS=-fcommon fixed this setup for my python 3.9
    – Rho Phi
    Dec 7, 2021 at 20:52
1

As of version 20.10, Ubuntu does not come with Python 2 installed as it is deprecated. It does have python 3. You use python3 to run python and pip3 to install modules.

0

DISCLAIMER: I am pretty new at using Ubuntu/Linux and Raspberry Pi, so I am not super knowledgeable about any of these systems or why things work a certain way. I'm going to give it a shot though since I haven't seen any other answers and I was having the same issue.


TL;DR

try:

sudo apt-get install RPi.GPIO

I think it may have something to do with pip not working for some reason.


Background

So for background, I have a python script that I was running on the Raspbian OS to measure the CPU temperature and control a few LEDs using the GPIO pins, but I needed a 64 bit operating system for some software and ended up going with lubuntu.

I did pretty much all the same steps as you and had the same errors. I think it was something to do with pip, because once I ran the above command it started working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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