bclayman bclayman - 6 months ago 183
Python Question

Flask ImportError: No Module Named Flask

I'm following the Flask tutorial here:

http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world


I get to the point where I try ./run.py and I get:

Traceback (most recent call last):
File "./run.py", line 3, in <module>
from app import app
File "/Users/benjaminclayman/Desktop/microblog/app/__init__.py", line 1, in <module>
from flask import Flask
ImportError: No module named flask


This looks similar to:

http://stackoverflow.com/questions/24188240/importerror-no-module-named-flask


But their solutions aren't helpful. For reference, I do have a folder named flask which one user mentioned may cause issues.

Answer

try deleting the virtualenv you created. create a new virtualenv

virtualenv flask

then

cd flask

let's activate the virtualenv

source bin/activate

now you should see (flask) on the left of the command line. Let's install flask

pip install flask

Then create a file hello.py

from flask import Flask
app = Flask(__name__)

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

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

and run it with

python hello.py