Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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__)

@app.route("/")
def main():
    return "Welcome!"

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

I run python app.py and get the following:

Traceback (most recent call last):
File "app.py", 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: /usr/local/bin/flask

which python gives me: /usr/bin/python

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

like image 813
avorter Avatar asked Oct 12 '16 02:10

avorter


People also ask

How do you fix an import error on a flask?

Second solution is First of all just create a new virtualenv with this command: virtualenv flask Then open it with: cd flask. Now you have to activate the virtualenv with this command: source bin/activate. Now just install flask: pip install flask. Now your error must be solved.


1 Answers

before run your app.py you need to activate your server by this command

. venv/bin/activate
like image 167
Atiar Talukdar Avatar answered Sep 23 '22 19:09

Atiar Talukdar