Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialPepe Suarez
18,267 PointsHow to run flask locally??
hey guys!! I know its a dumb question but I got used to do flask only in workspaces and now I can't figure out how to run it properly locally. I already have my virtual enviroment but how can I use it and run it in my computer? Is there any special text editor that can get the job done? Or does anyone knows a good tutorial to do this? Thanks for the help!!
4 Answers
Chris Freeman
Treehouse Moderator 68,457 PointsHi Pepe, I am current working on Flask in my home environment, too (Ubuntu 14.04). I am using virtualenvwrapper
which adds some convenient organization to virtualenv
# Setting up my virtual environment for Python 3 called "flasksocial"
$ mkvirtualenv --python=/usr/bin/python3 flasksocial
# install flask related modules (note I'm on the social network course. you might not need bcrypt, yet)
(flasksocial)$ pip install flask
(flasksocial)$ pip install peewee
(flasksocial)$ pip install flask-login
(flasksocial)$ pip install py-bcrypt
(flasksocial)$ pip install flask-bcrypt
(flasksocial)$ pip install flask-wtf
# app.py file will have HOST and PORT settings
(flasksocial)$ python app.py
After app.py is running, I can see it in my browser at http://0.0.0.0:8080.
Update: if you are only using virtualenv
then the process would be:
# Set up virtual environment (set Python 3 as default)
$ virtualenv -p /usr/bin/python3 flasksocial
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in flasksocial/bin/python3
Also creating executable in flasksocial/bin/python
Installing setuptools, pip...done
# Activate virtual environment
$ . flasksocial/bin/activate
# Updated prompt shows env name
(flasksocial)$
# Install flask related modules
(flasksocial)$ pip install flask
(flasksocial)$ pip install peewee
(flasksocial)$ pip install flask-login
(flasksocial)$ pip install py-bcrypt
(flasksocial)$ pip install flask-bcrypt
(flasksocial)$ pip install flask-wtf
Andreas cormack
Python Web Development Techdegree Graduate 33,011 Pointsgreat answer by Chris Freeman. Dont forget to activate your virtualenv once created.
#on linux
source bin/activate
# windows
Scripts/activate
Chris Freeman
Treehouse Moderator 68,457 PointsThe best part of using the virtualenvwrapper
is that it automatically invokes the env upon creation.
After that it's back to the workon
, deactivate
, etc. cycle.
For standard virtualenv
, you are right, I would have to activate it.
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsAhh cool thanks Chris Freeman did not know that. will try the virtualenvwrapper
Chris Freeman
Treehouse Moderator 68,457 PointsI updated my answer to include a regular virtualenv
setup.
Pepe Suarez
18,267 PointsAwesome Guys! Thanks!! I am getting there!! Just trying to understand better virtualenvwrapper lol!
Pepe Suarez
18,267 PointsHey guys I got everything working but I don't know why I can't see the app on the browser. The console is showing that the app is running in http://0.0.0.0:8000/ but when i go to this address nothing shows up! What am I doing wrong?? Thanks for the help!
Chris Freeman
Treehouse Moderator 68,457 PointsCan post what the console displays? Also post the line in app.py
that launches the flask server, and the values of HOST, PORT, and DEBUG.