Search code examples
pythonflaskraspberry-pigpio

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!


Solution

  • 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.