rewrite installation docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
discuss python version discuss all dependencies prefer python 3 in instructions [ci skip]
authored by David Lord · committed by David Lord · parent a80eab7 · Browse files · 1 file·+108 added−123 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+108 added−123 removed
- other:+108 added−123 removed
Provenance
- Commit
1fb43e3- Tree
5aeece1- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
a80eab7
1 file changed+108 added−123 removed
modified:docs/installation.rst+108 added-123 removed
1 unmodified line2 3 Installation4 ============5 6-Flask depends on some external libraries, like `Werkzeug7-<http://werkzeug.pocoo.org/>`_ and `Jinja2 <http://jinja.pocoo.org/>`_.8-Werkzeug is a toolkit for WSGI, the standard Python interface between web9-applications and a variety of servers for both development and deployment.10-Jinja2 renders templates.6+Python Version7+--------------8 12-So how do you get all that on your computer quickly? There are many ways you13-could do that, but the most kick-ass method is virtualenv, so let's have a look14-at that first.9+We recommend using the latest version of Python 3. Flask supports Python 3.310+and newer, Python 2.6 and newer, and PyPy.11 16-You will need Python 2.6 or newer to get started, so be sure to have an17-up-to-date Python 2.x installation. For using Flask with Python 3 have a18-look at :ref:`python3-support`.12+Dependencies13+------------14 20-.. _virtualenv:15+These distributions will be installed automatically when installing Flask.16 22-virtualenv23-----------17+* `Werkzeug`_ implements WSGI, the standard Python interface between18+ applications and servers.19+* `Jinja`_ is a template language that renders the pages your application20+ serves.21+* `MarkupSafe`_ comes with Jinja. It escapes untrusted input when rendering22+ templates to avoid injection attacks.23+* `ItsDangerous`_ securely signs data to ensure its integrity. This is used24+ to protect Flask's session cookie.25+* `Click`_ is a framework for writing command line applications. It provides26+ the ``flask`` command and allows adding custom management commands.27 25-Virtualenv is probably what you want to use during development, and if you have26-shell access to your production machines, you'll probably want to use it there,27-too.28+.. _Werkzeug: http://werkzeug.pocoo.org/29+.. _Jinja: http://jinja.pocoo.org/30+.. _MarkupSafe: https://pypi.python.org/pypi/MarkupSafe31+.. _ItsDangerous: https://pythonhosted.org/itsdangerous/32+.. _Click: http://click.pocoo.org/33 29-What problem does virtualenv solve? If you like Python as much as I do,30-chances are you want to use it for other projects besides Flask-based web31-applications. But the more projects you have, the more likely it is that you32-will be working with different versions of Python itself, or at least different33-versions of Python libraries. Let's face it: quite often libraries break34-backwards compatibility, and it's unlikely that any serious application will35-have zero dependencies. So what do you do if two or more of your projects have36-conflicting dependencies?34+Optional dependencies35+~~~~~~~~~~~~~~~~~~~~~36 38-Virtualenv to the rescue! Virtualenv enables multiple side-by-side39-installations of Python, one for each project. It doesn't actually install40-separate copies of Python, but it does provide a clever way to keep different41-project environments isolated. Let's see how virtualenv works.37+These distributions will not be installed automatically. Flask will detect and38+use them if you install them.39 40+* `Blinker`_ provides support for :ref:`signals`.41+* `SimpleJSON`_ is a fast JSON implementation that is compatible with42+ Python's ``json`` module. It is preferred for JSON operations if it is43+ installed.44 44-.. admonition:: A note on python3 and virtualenv45+.. _Blinker: https://pythonhosted.org/blinker/46+.. _SimpleJSON: https://simplejson.readthedocs.io/47 46- If you are planning on using python3 with the virtualenv, you don't need to47- install ``virtualenv``. Python3 has built-in support for virtual environments.48+Virtual environments49+--------------------50 49-If you are on Mac OS X or Linux, chances are that the following50-command will work for you::51+Use a virtual environment to manage the dependencies for your project, both in52+development and in production.53 52- $ sudo pip install virtualenv54+What problem does a virtual environment solve? The more Python projects you55+have, the more likely it is that you need to work with different versions of56+Python libraries, or even Python itself. Newer versions of libraries for one57+project can break compatibility in another project.58 54-It will probably install virtualenv on your system. Maybe it's even55-in your package manager. If you use Ubuntu, try::59+Virtual environments are independent groups of Python libraries, one for each60+project. Packages installed for one project will not affect other projects or61+the operating system's packages.62 57- $ sudo apt-get install python-virtualenv63+Python 3 comes bundled with the :mod:`venv` module to create virtual64+environments. If you're using a modern version of Python, you can continue on65+to the next section.66 59-If you are on Windows and don't have the ``easy_install`` command, you must60-install it first. Check the :ref:`windows-easy-install` section for more61-information about how to do that. Once you have it installed, run the same62-commands as above, but without the ``sudo`` prefix.67+If you're using Python 2, see :ref:`install-install-virtualenv` first.68 64-Creating a virtual environment65-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~69+.. _install-create-env:70 67-Once you have virtualenv installed, just fire up a shell and create68-your own environment. I usually create a project folder and a :file:`virtenv`69-folder within::71+Create an environment72+~~~~~~~~~~~~~~~~~~~~~73 71- $ mkdir myproject72- $ cd myproject74+Create a project folder and a :file:`venv` folder within:75 74-There is a little change in how you create a virtualenv depending on which python-version you are currently using.76+.. code-block:: sh77 76-**Python2**78+ mkdir myproject79+ cd myproject80+ python3 -m venv venv81 78-::82+On Windows:83 80- $ virtualenv virtenv81- New python executable in virtenv/bin/python82- Installing setuptools, pip............done.84+.. code-block:: bat85 84-**Python 3.6 and above**86+ py -3 -m venv venv87 86-::88+If you needed to install virtualenv because you are on an older version of89+Python, use the following command instead:90 88- $ python3 -m venv virtenv91+.. code-block:: sh92 90-Activating a virtual environment91-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~93+ virtualenv venv94 93-Now, whenever you want to work on a project, you only have to activate the94-corresponding environment. On OS X and Linux, do the following::95+On Windows:96 96- $ . virtenv/bin/activate97+.. code-block:: bat98 98-If you are a Windows user, the following command is for you::99+ \Python27\Scripts\virtualenv.exe venv100 100- $ virtenv\Scripts\activate101+Activate the environment102+~~~~~~~~~~~~~~~~~~~~~~~~103 102-Either way, you should now be using your virtualenv (notice how the prompt of103-your shell has changed to show the active environment).104+Before you work on your project, activate the corresponding environment:105 105-And if you want to go back to the real world, use the following command::106+.. code-block:: sh107 107- $ deactivate108+ . venv/bin/activate109 109-After doing this, the prompt of your shell should be as familiar as before.110+On Windows:111 111-Now, let's move on. Enter the following command to get Flask activated in your112-virtualenv::112+.. code-block:: bat113 114- $ pip install Flask114+ venv\Scripts\activate115 116-A few seconds later and you are good to go.116+Your shell prompt will change to show the name of the activated environment.117 118+Install Flask119+-------------120 119-System-Wide Installation120-------------------------121+Within the activated environment, use the following command to install Flask:122 122-This is possible as well, though I do not recommend it. Just run123-``pip`` with root privileges::123+.. code-block:: sh124 125- $ sudo pip install Flask125+ pip install Flask126 127-(On Windows systems, run it in a command-prompt window with administrator128-privileges, and leave out ``sudo``.)127+Living on the edge128+~~~~~~~~~~~~~~~~~~129 130+If you want to work with the latest Flask code before it's released, install or131+update the code from the master branch:132 131-Living on the Edge132-------------------133+.. code-block:: sh134 134-If you want to work with the latest version of Flask, there are two ways: you135-can either let ``pip`` pull in the development version, or you can tell136-it to operate on a git checkout. Either way, virtualenv is recommended.135+ pip install -U https://github.com/pallets/flask/archive/master.tar.gz136 138-Get the git checkout in a new virtualenv and run in development mode::137+.. _install-install-virtualenv:138 140- $ git clone https://github.com/pallets/flask.git141- Initialized empty Git repository in ~/dev/flask/.git/142- $ cd flask143- $ virtualenv virtenv144- New python executable in virtenv/bin/python145- Installing setuptools, pip............done.146- $ . virtenv/bin/activate147- $ python setup.py develop148- ...149- Finished processing dependencies for Flask139+Install virtualenv140+------------------141 151-This will pull in the dependencies and activate the git head as the current152-version inside the virtualenv. Then all you have to do is run ``git pull153-origin`` to update to the latest version.142+If you are using Python 2, the venv module is not available. Instead,143+install `virtualenv`_.144 155-.. _windows-easy-install:145+On Linux, virtualenv is provided by your package manager:146 157-`pip` and `setuptools` on Windows158----------------------------------147+.. code-block:: sh148 160-Sometimes getting the standard "Python packaging tools" like ``pip``, ``setuptools``161-and ``virtualenv`` can be a little trickier, but nothing very hard. The crucial162-package you will need is pip - this will let you install163-anything else (like virtualenv). Fortunately there is a "bootstrap script"164-you can run to install.149+ # Debian, Ubuntu150+ sudo apt-get install python-virtualenv151 166-If you don't currently have ``pip``, then `get-pip.py` will install it for you.152+ # CentOS, Fedora153+ sudo yum install python-virtualenv154 168-`get-pip.py`_155+ # Arch156+ sudo pacman -S python-virtualenv157 170-It should be double-clickable once you download it. If you already have ``pip``,171-you can upgrade them by running::158+If you are on Mac OS X or Windows, download `get-pip.py`_, then:159 173- > pip install --upgrade pip setuptools160+.. code-block:: sh161 175-Most often, once you pull up a command prompt you want to be able to type ``pip``176-and ``python`` which will run those things, but this might not automatically happen177-on Windows, because it doesn't know where those executables are (give either a try!).162+ sudo python2 Downloads/get-pip.py163+ sudo python2 -m pip install virtualenv164 179-To fix this, you should be able to navigate to your Python install directory180-(e.g :file:`C:\Python27`), then go to :file:`Tools`, then :file:`Scripts`, then find the181-:file:`win_add2path.py` file and run that. Open a **new** Command Prompt and182-check that you can now just type ``python`` to bring up the interpreter.165+On Windows, as an administrator:166 184-Finally, to install `virtualenv`_, you can simply run::167+.. code-block:: bat168 186- > pip install virtualenv169+ \Python27\python.exe Downloads\get-pip.py170+ \Python27\python.exe -m pip install virtualenv171 188-Then you can be off on your way following the installation instructions above.172+Now you can continue to :ref:`install-create-env`.173 174+.. _virtualenv: https://virtualenv.pypa.io/175 .. _get-pip.py: https://bootstrap.pypa.io/get-pip.py