GPIO on raspberry pi

Solution 1:

In the terminal type:

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

If you are using Python 3.x run these commands.

sudo apt update
sudo apt upgrade
sudo apt install python3-pip python3-dev
pip3 install --user 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.