[Solved] from Flask import Flask ImportError: No module named Flask

I am following the tutorial here.

My file looks like this:

from flask import Flask
app = Flask(__name__)

def main():
    return "Welcome!"

if __name__ == "__main__":

I run python and get the following:

Traceback (most recent call last):
File "", line 1, in <module>
from flask import Flask
ImportError: No module named Flask

I do have flask installed. I was thinking it’s a $PATH issue. I don’t really know where to begin as far as troubleshooting goes.

which flask gives me:

which python gives me:

Any help is much appreciated, there are other similar issues out there but those solutions have not helped. Happy to answer any questions. Thank you.

Answers to questions:

Q. Which Python version? A. Python 2.7.10

Q. How did you install Flask? A. pip install flask

Enquirer: avorter


Solution #1:

before run your you need to activate your server by this command

. venv/bin/activate
Respondent: avorter

Solution #2:

It looks like that you are using linux, if you are using ubuntu
try: (similar for other linux distributions)

sudo apt-get install python-flask

It helped me install many packages that pip fails to install.

Respondent: Atiar Talukdar

Solution #3:

The app package and file need to be in the same directory level.


Above folder structure should fix.

P.S. pip install all necessary packages into virtual enviroment (venv in my example)

Respondent: Coco

Solution #4:

You can try to uninstall and to reinstall it again(you can follow this link for more detaile) :

You can take anaconda and there you can make enviroment for every version of python .Anaconda is getting very easy from this link:

Then you can open terminal and pip install flask (if you are on windows) or conda pip install flask .

I recommand to use python3.5 not python 2.7 .

Respondent: Temi Fakunle

Solution #5:

if you are on Python 3, try installing flask with

pip3 install flask

and if you fail (you are likely to get an command prompt error as below)

'pip3' is not recognized as an internal or external command,
operable program or batch file.


py -3 -mpip install flask on windows

this command installs flask module on python 3, and then you could run your script.
worked for me!

Respondent: Bogdan Bibina

Solution #6:

Python 3 :

pip3 install flask

Python 2 :

pip install flask

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy