Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/studio/static/doc/flask-docs/_sources/installation.txt
blob: eb645bdc827dcf9c431f7e8c0a76e046d5d1d553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
.. _installation:

Installation
============

Flask depends on two external libraries, `Werkzeug
<http://werkzeug.pocoo.org/>`_ and `Jinja2 <http://jinja.pocoo.org/2/>`_.
Werkzeug is a toolkit for WSGI, the standard Python interface between web
applications and a variety of servers for both development and deployment.
Jinja2 renders templates.

So how do you get all that on your computer quickly?  There are many ways
which this section will explain, but the most kick-ass method is
virtualenv, so let's look at that first.

Either way, you will need Python 2.5 or higher to get started, so be sure
to have an up to date Python 2.x installation.  At the time of writing,
the WSGI specification is not yet finalized for Python 3, so Flask cannot
support the 3.x series of Python.

.. _virtualenv:

virtualenv
----------

Virtualenv is probably what you want to use during development, and in
production too if you have shell access there.

What problem does virtualenv solve?  If you like Python as I do,
chances are you want to use it for other projects besides Flask-based
web applications.  But the more projects you have, the more likely it is
that you will be working with different versions of Python itself, or at
least different versions of Python libraries.  Let's face it; quite often
libraries break backwards compatibility, and it's unlikely that any serious
application will have zero dependencies.  So what do you do if two or more
of your projects have conflicting dependencies?

Virtualenv to the rescue!  It basically enables multiple side-by-side
installations of Python, one for each project.  It doesn't actually
install separate copies of Python, but it does provide a clever way
to keep different project environments isolated.

So let's see how virtualenv works!

If you are on Mac OS X or Linux, chances are that one of the following two
commands will work for you::

    $ sudo easy_install virtualenv

or even better::

    $ sudo pip install virtualenv

One of these will probably install virtualenv on your system.  Maybe it's
even in your package manager.  If you use Ubuntu, try::

    $ sudo apt-get install python-virtualenv

If you are on Windows and don't have the `easy_install` command, you must
install it first.  Check the :ref:`windows-easy-install` section for more
information about how to do that.  Once you have it installed, run the
same commands as above, but without the `sudo` prefix.

Once you have virtualenv installed, just fire up a shell and create
your own environment.  I usually create a project folder and an `env`
folder within::

    $ mkdir myproject
    $ cd myproject
    $ virtualenv env
    New python executable in env/bin/python
    Installing setuptools............done.

Now, whenever you want to work on a project, you only have to activate
the corresponding environment.  On OS X and Linux, do the following::

    $ . env/bin/activate

(Note the space between the dot and the script name.  The dot means that
this script should run in the context of the current shell.  If this command
does not work in your shell, try replacing the dot with ``source``)

If you are a Windows user, the following command is for you::

    $ env\scripts\activate

Either way, you should now be using your virtualenv (see how the prompt of
your shell has changed to show the virtualenv).

Now you can just enter the following command to get Flask activated in
your virtualenv::

    $ easy_install Flask

A few seconds later you are good to go.


System Wide Installation
------------------------

This is possible as well, but I do not recommend it.  Just run
`easy_install` with root rights::

    $ sudo easy_install Flask

(Run it in an Admin shell on Windows systems and without `sudo`).


Living on the Edge
------------------

If you want to work with the latest version of Flask, there are two ways: you
can either let `easy_install` pull in the development version, or tell it
to operate on a git checkout.  Either way, virtualenv is recommended.

Get the git checkout in a new virtualenv and run in development mode::

    $ git clone http://github.com/mitsuhiko/flask.git
    Initialized empty Git repository in ~/dev/flask/.git/
    $ cd flask
    $ virtualenv env
    $ . env/bin/activate
    New python executable in env/bin/python
    Installing setuptools............done.
    $ python setup.py develop
    ...
    Finished processing dependencies for Flask

This will pull in the dependencies and activate the git head as the current
version inside the virtualenv.  Then you just have to ``git pull origin``
to get the latest version.

To just get the development version without git, do this instead::

    $ mkdir flask
    $ cd flask
    $ virtualenv env
    $ . env/bin/activate
    New python executable in env/bin/python
    Installing setuptools............done.
    $ easy_install Flask==dev
    ...
    Finished processing dependencies for Flask==dev

.. _windows-easy-install:

`easy_install` on Windows
-------------------------

On Windows, installation of `easy_install` is a little bit trickier because
slightly different rules apply on Windows than on Unix-like systems, but
it's not difficult.  The easiest way to do it is to download the
`ez_setup.py`_ file and run it.  The easiest way to run the file is to
open your downloads folder and double-click on the file.

Next, add the `easy_install` command and other Python scripts to the
command search path, by adding your Python installation's Scripts folder
to the `PATH` environment variable.  To do that, right-click on the
"Computer" icon on the Desktop or in the Start menu, and choose
"Properties".  Then, on Windows Vista and Windows 7 click on "Advanced System
settings"; on Windows XP, click on the "Advanced" tab instead.  Then click
on the "Environment variables" button and double click on the "Path"
variable in the "System variables" section.  There append the path of your
Python interpreter's Scripts folder; make sure you delimit it from
existing values with a semicolon.  Assuming you are using Python 2.6 on
the default path, add the following value::

    ;C:\Python26\Scripts

Then you are done.  To check that it worked, open the Command Prompt and
execute ``easy_install``.  If you have User Account Control enabled on
Windows Vista or Windows 7, it should prompt you for admin privileges.


.. _ez_setup.py: http://peak.telecommunity.com/dist/ez_setup.py