2

I keep getting this error when running the basic program.

ImportError: No module named flask

Here's the basic prog:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

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

when I run which Flask on the folder it doesn't return the location. But if I run the pip install from there it says it's already installed.

5
  • 2
    How are you running it? Is the virtualenv activated? Commented Jun 7, 2013 at 18:46
  • Activated the folder with source.. so when I run which pip I see the right folder structure. Commented Jun 7, 2013 at 18:48
  • 2
    Are you running pip from within the virtualenv? How did you create it? Commented Jun 7, 2013 at 18:48
  • Well... thanks Wooble for asking the right question. Ran it from terminal and it worked. Commented Jun 7, 2013 at 18:51
  • 2
    Did you do... source bin/activate; pip install flask; python file.py Commented Jun 7, 2013 at 18:51

2 Answers 2

4

If your want to create a project with Flask and VirtualENV, you should follow the steps below, I sure that you will not meet the error above.

Step 1: Create project directory and initial virtualenv directory

mkdir project 
cd project
virtualenv -p /usr/bin/python env

Step 2: Activate your virtual enviroment

source env/bin/activate

Step 3: Create requirements.txt file and add the content below:

Flask

Step 4: Install the packets with PIP

pip install -r requirements.txt

Step 5: Create your project file. E.g: run.py

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

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

Step 6: Finally, run your app

python run.py

You will have some little works before publishing your code to repositories: init git, create gitignore ...

Sign up to request clarification or add additional context in comments.

Comments

0

I hope you had installed virtualenv and if you have create the virtual environment (virtualenv), you have to use . . venv/bin/activate command to activate the enviroment in unix or OSx. Hope you will get information from this source

http://flask.pocoo.org/docs/installation/#installation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.