Reputation: 29
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.
Upvotes: 2
Views: 9819
Reputation: 5376
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 ...
Upvotes: 4
Reputation: 22644
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
Upvotes: 0