error while installing RPi.GPIO as "ERROR: Command errored out with exit status 1:"

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.


Solution 1:

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

Solution 2:

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.