Site5 - Built For Designers & Developers MENU
Home  ›  Python  ›  Python: How to install Flask

Python: How to install Flask

5 Comments

In this article, we will show you how to install Flask.

Let’s start by making a folder we can download the stuff we need to.

mkdir ~/tmpdownload

Let’s move into that folder…

cd ~/tmpdownload

Let’s download the files and unzip them…

wget http://pypi.python.org/packages/source/F/Flask/Flask-0.9.tar.gz
tar xzf Flask-*.tar.gz && rm Flask-*.tar.gz

Now lets move into the folder that we unzipped…

cd F*

It’s time to do the install itself…

python2.6 setup.py install --user

Now lets move into our public_html folder so we can start adding the needed files…

cd ~/public_html

Lets create the htaccess file we are going to need…

nano .htaccess

Once Nano is open, paste the following…
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.fcgi/$1 [QSA,L]

To save it, simply press Ctrl + X, Y then Enter.

Now lets make the fcgi file we need…

nano index.fcgi

Paste the following…

#!/usr/bin/env python2.6
from flask import Flask
from flup.server.fcgi import WSGIServer
app = Flask(__name__)
 
@app.route('/')
def hello():
	return "Hello world!"
 
WSGIServer(app).run()

To save it, simply press Ctrl + X, Y then Enter.

Time to make it executable…

chmod +x index.fcgi

Now lets clean up that download folder we made at the start…

rm -r ~/tmpdownload

That’s it!

Please Note: In some situations, you may not notice changes made to your code/website. This can be resolved by killing/stopping the index.fcgi process over SSH. For more information on how to do this, please click here.

Still have a question? Or need help?
See an error in this article or want to suggest a missing topic? Please leave us a comment below! If you need technical support with your account, please email us, chat live with a representative, or call us!

5 Comments

  • Thank you for the guide. This works!

  • How do we install Flask into a virtual environment?

    A up-to-date guide like…
    http://kb.site5.com/python/how-to-setup-django-in-a-virtual-environment/
    except for Flask would be great!

    • Hi Gregory!

      You’re in luck, we have one of those as well! You can access our Flask instructions here: http://kb.site5.com/python/how-to-install-flask/

      • The problem with http://kb.site5.com/python/how-to-install-flask/ is it does NOT mention the virtualenv tool used to create project specific environments.

        The Guide for django tells how to use virtualenv.

        Would I do steps 1 thru 7 from “http://kb.site5.com/python/how-to-setup-django-in-a-virtual-environment/” for a flask virtualenv as well?

        Creating Local path setup in Step 3 and symlink in Step 4, etc?

        • Hi Gregory!

          Thank you for clarifying and those are excellent questions. If you are running into issues following our install instructions, please do contact our support team by opening a ticket through your backstage panel and we’ll find out exactly what is needed so your install is completed properly and then get the install documentation fixed up. Thanks!

Money Back Guarantees
Click to verify BBB accreditation and to see a BBB report.