installation.rst
This file
Path
docs/installation.rst
173 lines · 6.1 KiB
Last changed by
Added notes on Python 3Armin Ronacherbefore adoption0ac9582
History of this fileTake 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.6 or higher to get started, so be sure to have an17up-to-date Python 2.x installation. For using Flask with Python 3 have a18look at :ref:`python3-support`.1920.. _virtualenv:2122virtualenv23----------2425Virtualenv is probably what you want to use during development, and if you have26shell access to your production machines, you'll probably want to use it there,27too.2829What problem does virtualenv solve? If you like Python as much as I do,30chances are you want to use it for other projects besides Flask-based web31applications. But the more projects you have, the more likely it is that you32will be working with different versions of Python itself, or at least different33versions of Python libraries. Let's face it: quite often libraries break34backwards compatibility, and it's unlikely that any serious application will35have zero dependencies. So what do you do if two or more of your projects have36conflicting dependencies?3738Virtualenv to the rescue! Virtualenv enables multiple side-by-side39installations of Python, one for each project. It doesn't actually install40separate copies of Python, but it does provide a clever way to keep different41project environments isolated. Let's see how virtualenv works.4243If you are on Mac OS X or Linux, chances are that one of the following two44commands will work for you::4546 $ sudo easy_install virtualenv4748or even better::4950 $ sudo pip install virtualenv5152One of these will probably install virtualenv on your system. Maybe it's even53in your package manager. If you use Ubuntu, try::5455 $ sudo apt-get install python-virtualenv5657If you are on Windows and don't have the `easy_install` command, you must58install it first. Check the :ref:`windows-easy-install` section for more59information about how to do that. Once you have it installed, run the same60commands as above, but without the `sudo` prefix.6162Once you have virtualenv installed, just fire up a shell and create63your own environment. I usually create a project folder and a `venv`64folder within::6566 $ mkdir myproject67 $ cd myproject68 $ virtualenv venv69 New python executable in venv/bin/python70 Installing distribute............done.7172Now, whenever you want to work on a project, you only have to activate the73corresponding environment. On OS X and Linux, do the following::7475 $ . venv/bin/activate7677If you are a Windows user, the following command is for you::7879 $ venv\scripts\activate8081Either way, you should now be using your virtualenv (notice how the prompt of82your shell has changed to show the active environment).8384Now you can just enter the following command to get Flask activated in your85virtualenv::8687 $ pip install Flask8889A few seconds later and you are good to go.909192System-Wide Installation93------------------------9495This is possible as well, though I do not recommend it. Just run96`pip` with root privileges::9798 $ sudo pip install Flask99100(On Windows systems, run it in a command-prompt window with administrator101privileges, and leave out `sudo`.)102103104Living on the Edge105------------------106107If you want to work with the latest version of Flask, there are two ways: you108can either let `pip` pull in the development version, or you can tell109it to operate on a git checkout. Either way, virtualenv is recommended.110111Get the git checkout in a new virtualenv and run in development mode::112113 $ git clone http://github.com/mitsuhiko/flask.git114 Initialized empty Git repository in ~/dev/flask/.git/115 $ cd flask116 $ virtualenv venv --distribute117 New python executable in venv/bin/python118 Installing distribute............done.119 $ . venv/bin/activate120 $ python setup.py develop121 ...122 Finished processing dependencies for Flask123124This will pull in the dependencies and activate the git head as the current125version inside the virtualenv. Then all you have to do is run ``git pull126origin`` to update to the latest version.127128To just get the development version without git, do this instead::129130 $ mkdir flask131 $ cd flask132 $ virtualenv venv --distribute133 $ . venv/bin/activate134 New python executable in venv/bin/python135 Installing distribute............done.136 $ pip install Flask==dev137 ...138 Finished processing dependencies for Flask==dev139140.. _windows-easy-install:141142`pip` and `distribute` on Windows143-----------------------------------144145On Windows, installation of `easy_install` is a little bit trickier, but still146quite easy. The easiest way to do it is to download the147`distribute_setup.py`_ file and run it. The easiest way to run the file is to148open your downloads folder and double-click on the file.149150Next, add the `easy_install` command and other Python scripts to the151command search path, by adding your Python installation's Scripts folder152to the `PATH` environment variable. To do that, right-click on the153"Computer" icon on the Desktop or in the Start menu, and choose "Properties".154Then click on "Advanced System settings" (in Windows XP, click on the155"Advanced" tab instead). Then click on the "Environment variables" button.156Finally, double-click on the "Path" variable in the "System variables" section,157and add the path of your Python interpreter's Scripts folder. Be sure to158delimit it from existing values with a semicolon. Assuming you are using159Python 2.7 on the default path, add the following value::160161162 ;C:\Python27\Scripts163164And you are done! To check that it worked, open the Command Prompt and execute165``easy_install``. If you have User Account Control enabled on Windows Vista or166Windows 7, it should prompt you for administrator privileges.167168Now that you have ``easy_install``, you can use it to install ``pip``::169170 > easy_install pip171172173.. _distribute_setup.py: http://python-distribute.org/distribute_setup.py