Skip to content
Myr

installation.rst

This file

Path

docs/installation.rst

165 lines · 5.9 KiB

Last changed by

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

History of this file

Take it

The walk stopped after 200 commits: lines older than 86e8267 point at it.

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 1–42why, one step back
1.. _installation:
23Installation4============56Flask depends on some external libraries, like `Werkzeug7<http://werkzeug.pocoo.org/>`_ and `Jinja2 <http://jinja.pocoo.org/>`_.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 newer 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.42

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

lines 43–44why, one step back
43If you are on Mac OS X or Linux, chances are that the following
44command will work for you::

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 45–47why, one step back
45
46 $ sudo pip install virtualenv47

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

line 48why, one step back
48It will probably install virtualenv on your system. Maybe it's even

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 49–52why, one step back
49in your package manager. If you use Ubuntu, try::
5051 $ sudo apt-get install python-virtualenv52

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

line 53why, one step back
53If you are on Windows and don't have the ``easy_install`` command, you must

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 54–55why, one step back
54install it first. Check the :ref:`windows-easy-install` section for more
55information about how to do that. Once you have it installed, run the same

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

line 56why, one step back
56commands as above, but without the ``sudo`` prefix.

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 57–97why, one step back
57
58Once you have virtualenv installed, just fire up a shell and create59your own environment. I usually create a project folder and a :file:`venv`60folder within::6162 $ mkdir myproject63 $ cd myproject64 $ virtualenv venv65 New python executable in venv/bin/python66 Installing setuptools, pip............done.6768Now, whenever you want to work on a project, you only have to activate the69corresponding environment. On OS X and Linux, do the following::7071 $ . venv/bin/activate7273If you are a Windows user, the following command is for you::7475 $ venv\scripts\activate7677Either way, you should now be using your virtualenv (notice how the prompt of78your shell has changed to show the active environment).7980And if you want to go back to the real world, use the following command::8182 $ deactivate8384After doing this, the prompt of your shell should be as familiar as before.8586Now, let's move on. Enter the following command to get Flask activated in your87virtualenv::8889 $ pip install Flask9091A few seconds later and you are good to go.929394System-Wide Installation95------------------------9697This is possible as well, though I do not recommend it. Just run

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

line 98why, one step back
98``pip`` with root privileges::

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 99–102why, one step back
99
100 $ sudo pip install Flask101102(On Windows systems, run it in a command-prompt window with administrator

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

line 103why, one step back
103privileges, and leave out ``sudo``.)

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 104–109why, one step back
104
105106Living on the Edge107------------------108109If you want to work with the latest version of Flask, there are two ways: you

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

line 110why, one step back
110can either let ``pip`` pull in the development version, or you can tell

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 111–114why, one step back
111it to operate on a git checkout. Either way, virtualenv is recommended.
112113Get the git checkout in a new virtualenv and run in development mode::114

Change to Pallets projectJosé Carlos Garcíabefore adoption567fff9

line 115why, one step back
115 $ git clone http://github.com/pallets/flask.git

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 116–134why, one step back
116 Initialized empty Git repository in ~/dev/flask/.git/
117 $ cd flask118 $ virtualenv venv119 New python executable in venv/bin/python120 Installing setuptools, pip............done.121 $ . venv/bin/activate122 $ python setup.py develop123 ...124 Finished processing dependencies for Flask125126This will pull in the dependencies and activate the git head as the current127version inside the virtualenv. Then all you have to do is run ``git pull128origin`` to update to the latest version.129130.. _windows-easy-install:131132`pip` and `setuptools` on Windows133---------------------------------134

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

lines 135–139why, one step back
135Sometimes getting the standard "Python packaging tools" like ``pip``, ``setuptools``
136and ``virtualenv`` can be a little trickier, but nothing very hard. The crucial137package you will need is pip - this will let you install138anything else (like virtualenv). Fortunately there is a "bootstrap script"139you can run to install.

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

line 140why, one step back
140

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

line 141why, one step back
141If you don't currently have ``pip``, then `get-pip.py` will install it for you.

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 142–144why, one step back
142
143`get-pip.py`_144

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

line 145why, one step back
145It should be double-clickable once you download it. If you already have ``pip``,

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 146–149why, one step back
146you can upgrade them by running::
147148 > pip install --upgrade pip setuptools149

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

lines 150–151why, one step back
150Most often, once you pull up a command prompt you want to be able to type ``pip``
151and ``python`` which will run those things, but this might not automatically happen

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 152–154why, one step back
152on Windows, because it doesn't know where those executables are (give either a try!).
153154To fix this, you should be able to navigate to your Python install directory

Merge pull request #1755 from bdh1011/patch-1Markus Unterwaditzerbefore adoptionc9b29f4

line 155why, one step back
155(e.g :file:`C:\Python27`), then go to :file:`Tools`, then :file:`Scripts`, then find the

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

line 156why, one step back
156:file:`win_add2path.py` file and run that. Open a **new** Command Prompt and

Update installation documentation for using 'pip' command (#1920)Olexander Yermakovbefore adoptionb7a0cc6

line 157why, one step back
157check that you can now just type ``python`` to bring up the interpreter.

Merge pull request #1378 from cbron/masterKeyan Pishdadianbefore adoption86e8267

lines 158–164why, one step back
158
159Finally, to install `virtualenv`_, you can simply run::160161 > pip install virtualenv162163Then you can be off on your way following the installation instructions above.164

Merge pull request #1759 from gunbei/update-get-pip.py-locationMarkus Unterwaditzerbefore adoption3d78573

line 165why, one step back
165.. _get-pip.py: https://bootstrap.pypa.io/get-pip.py