Skip to content
Myr

installation.rst

This file

Path

docs/installation.rst

174 lines · 6.2 KiB

Last changed by

Use 'venv' consistently for virtualenv directory.Ron DuPlainbefore adoption0d2ffc0

History of this file

Take it

1.. _installation:23Installation4============56Flask depends on two external libraries, `Werkzeug7<http://werkzeug.pocoo.org/>`_ and `Jinja2 <http://jinja.pocoo.org/2/>`_.8Werkzeug is a toolkit for WSGI, the standard Python interface between web9applications and a variety of servers for both development and deployment.10Jinja2 renders templates.1112So how do you get all that on your computer quickly?  There are many ways you13could do that, but the most kick-ass method is virtualenv, so let's have a look14at that first.1516You will need Python 2.5 or higher to get started, so be sure to have an17up-to-date Python 2.x installation.  At the time of writing, the WSGI18specification has not yet been finalized for Python 3, so Flask cannot support19the 3.x series of Python.2021.. _virtualenv:2223virtualenv24----------2526Virtualenv is probably what you want to use during development, and if you have27shell access to your production machines, you'll probably want to use it there,28too.2930What problem does virtualenv solve?  If you like Python as much as I do,31chances are you want to use it for other projects besides Flask-based web32applications.  But the more projects you have, the more likely it is that you33will be working with different versions of Python itself, or at least different34versions of Python libraries.  Let's face it: quite often libraries break35backwards compatibility, and it's unlikely that any serious application will36have zero dependencies.  So what do you do if two or more of your projects have37conflicting dependencies?3839Virtualenv to the rescue!  Virtualenv enables multiple side-by-side40installations of Python, one for each project.  It doesn't actually install41separate copies of Python, but it does provide a clever way to keep different42project environments isolated.  Let's see how virtualenv works.4344If you are on Mac OS X or Linux, chances are that one of the following two45commands will work for you::4647    $ sudo easy_install virtualenv4849or even better::5051    $ sudo pip install virtualenv5253One of these will probably install virtualenv on your system.  Maybe it's even54in your package manager.  If you use Ubuntu, try::5556    $ sudo apt-get install python-virtualenv5758If you are on Windows and don't have the `easy_install` command, you must59install it first.  Check the :ref:`windows-easy-install` section for more60information about how to do that.  Once you have it installed, run the same61commands as above, but without the `sudo` prefix.6263Once you have virtualenv installed, just fire up a shell and create64your own environment.  I usually create a project folder and a `venv`65folder within::6667    $ mkdir myproject68    $ cd myproject69    $ virtualenv venv70    New python executable in venv/bin/python71    Installing distribute............done.7273Now, whenever you want to work on a project, you only have to activate the74corresponding environment.  On OS X and Linux, do the following::7576    $ . venv/bin/activate7778If you are a Windows user, the following command is for you::7980    $ venv\scripts\activate8182Either way, you should now be using your virtualenv (notice how the prompt of83your shell has changed to show the active environment).8485Now you can just enter the following command to get Flask activated in your86virtualenv::8788    $ pip install Flask8990A few seconds later and you are good to go.919293System-Wide Installation94------------------------9596This is possible as well, though I do not recommend it.  Just run97`pip` with root privileges::9899    $ sudo pip install Flask100101(On Windows systems, run it in a command-prompt window with administrator102privileges, and leave out `sudo`.)103104105Living on the Edge106------------------107108If you want to work with the latest version of Flask, there are two ways: you109can either let `pip` pull in the development version, or you can tell110it to operate on a git checkout.  Either way, virtualenv is recommended.111112Get the git checkout in a new virtualenv and run in development mode::113114    $ git clone http://github.com/mitsuhiko/flask.git115    Initialized empty Git repository in ~/dev/flask/.git/116    $ cd flask117    $ virtualenv venv --distribute118    New python executable in venv/bin/python119    Installing distribute............done.120    $ . venv/bin/activate121    $ python setup.py develop122    ...123    Finished processing dependencies for Flask124125This will pull in the dependencies and activate the git head as the current126version inside the virtualenv.  Then all you have to do is run ``git pull127origin`` to update to the latest version.128129To just get the development version without git, do this instead::130131    $ mkdir flask132    $ cd flask133    $ virtualenv venv --distribute134    $ . venv/bin/activate135    New python executable in venv/bin/python136    Installing distribute............done.137    $ pip install Flask==dev138    ...139    Finished processing dependencies for Flask==dev140141.. _windows-easy-install:142143`pip` and `distribute` on Windows144-----------------------------------145146On Windows, installation of `easy_install` is a little bit trickier, but still147quite easy.  The easiest way to do it is to download the148`distribute_setup.py`_ file and run it.  The easiest way to run the file is to149open your downloads folder and double-click on the file.150151Next, add the `easy_install` command and other Python scripts to the152command search path, by adding your Python installation's Scripts folder153to the `PATH` environment variable.  To do that, right-click on the154"Computer" icon on the Desktop or in the Start menu, and choose "Properties".155Then click on "Advanced System settings" (in Windows XP, click on the156"Advanced" tab instead).  Then click on the "Environment variables" button.157Finally, double-click on the "Path" variable in the "System variables" section,158and add the path of your Python interpreter's Scripts folder. Be sure to159delimit it from existing values with a semicolon.  Assuming you are using160Python 2.7 on the default path, add the following value::161162163    ;C:\Python27\Scripts164165And you are done!  To check that it worked, open the Command Prompt and execute166``easy_install``.  If you have User Account Control enabled on Windows Vista or167Windows 7, it should prompt you for administrator privileges.168169Now that you have ``easy_install``, you can use it to install ``pip``::170171    > easy_install pip172173174.. _distribute_setup.py: http://python-distribute.org/distribute_setup.py