Python Forum

Full Version: Error: "ModuleNotFoundError: No module named 'RPi'"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!

I am following this how-to: https://www.tomshardware.com/how-to/turn...spberry-pi

I am currently on the second to last step. I run the "make run" command. I received the following error

Traceback (most recent call last): File "app.py", line 2, in <module> import RPi.GPIO as GPIO ModuleNotFoundError: No module named 'RPi' make: *

I have tryed many things, and any help would be greatly appreciated! Have a good day!



In case it matters, this is on a Pi Zero 2 W running Raspberry Pi Os Buster
Can you post your code?
So it is a large folder full of a bunch of folders full of code. This is the code in app.py which is where it say's the error was from.

The error is:Traceback (most recent call last): File "app.py", line 2, in <module> import RPi.GPIO as GPIO ModuleNotFoundError: No module named 'RPi' make: *

Below is the code:

import RPi.GPIO as GPIO
import time
import logging
from google_assistant import GoogleAssistant


assistant = GoogleAssistant()
logging.basicConfig(level=logging.INFO)


def phone_picked_up():
    """Called when the phone is picked up"""
    logging.info('Receiver picked up')
    assistant.assist()


def phone_hung_up():
    """Called when the phone is hung up"""
    logging.info('Receiver hung up')


def listen_for_hook_state_change():
    """Continuously listens for pickup/hangup of the hook"""
    pin_number = 18
    GPIO.setmode(RPi.GPIO.BOARD)
    GPIO.setup(pin_number, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    try:
        while True:
            pin_current = GPIO.input(pin_number)
            if pin_current == 1:
                phone_picked_up()
            else:
                phone_hung_up()
            while GPIO.input(pin_number) == pin_current:
                time.sleep(0.1)
    except KeyboardInterrupt:
        print('Exiting...')
        GPIO.cleanup()


if __name__ == "__main__":
    listen_for_hook_state_change()
https://pypi.org/project/RPi.GPIO/
try running pip cmd on raspberry pi
Sorry, I tried that already!