Skip to content
Advertisement

Python “ModuleNotFoundError: No module named ‘flask'”

I am a beginner with the python programming. I have python 3 installed in my local system. I coding along as part of a tutorial video and as part of the tutorial, i have created a virtual environment and created an app.py file with the below content.

from flask import Flask

app = Flask(__name__)

@app.route("/")
def index():
    return "Hello, World!"

if __name__ == "__main__":
    app.run()

I have installed all the dependencies like flask and pytest in the virtual environment as per the tutorial using gitbash.But when i run the command python3 app.py in gitbash i get the below error message

 File "C:pathPythonpython-github-actions-examplesrcapp.py", line 1, in <module>
    from flask import Flask
ModuleNotFoundError: No module named 'flask'
(myvenv)

I checked the python version and it is python 3.9.7

If i run python app.py i get the output. Why is it not running even though correct version is installed

Any idea why ?

Advertisement

Answer

Try to delete the venv or make a new one.

  1. Then create a new venv like this: virtualenv flask

  2. Go to the flask directory : cd flask

  3. Activate it: scriptsactivate

    • You should see (flask) on the left of the command line.
  4. Install flask again: pip install flask

  5. Run your file again.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement