Matjaž Meža
Matjaž Meža

Reputation: 47

Flask error: [ModuleNotFoundError: No module named 'RPi']

I am making a simple Flask app on Raspberry pi, but I cannot include import RPi.GPIO as GPIO in python code. This is the output error:

 * Serving Flask app "rgbw.py"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
Usage: flask run [OPTIONS]

Error: While importing "rgbw", an ImportError was raised:

Traceback (most recent call last):
  File "/var/www/html/rgbw/venv/lib/python3.7/site-packages/flask/cli.py", line 240, in locate_app
    __import__(module_name)
  File "/var/www/html/rgbw/rgbw.py", line 5, in <module>
    import RPi.GPIO as GPIO
ModuleNotFoundError: No module named 'RPi'

I have installed GPIO inside the virtual environment, so I don't know why it doesn't want to work.

Thanks for help!

Upvotes: 1

Views: 3745

Answers (2)

Ivo de Man
Ivo de Man

Reputation: 1

Interesting... I tried pip install RPi.GPIO, and it didn't solve my problem (working ony when running the python program from Geany, but not from the terminal).

sudo apt-get -y install python3-rpi.gpio solved the issue, making it possible to run my program from the terminal.

Upvotes: 0

avt613
avt613

Reputation: 309

Have you got RPi.GPIO installed? (You can check by running pip freeze in the virtual environment.) If not you can install it with: pip install RPi.GPIO

import RPi.GPIO as GPIO is trying to import the function GPIO from the library RPi.GPIO which is not the same library as GPIO.

I hope this solves your problem, if not please add a copy of your code and pip freeze to your question.

Upvotes: 1

Related Questions