installation.rst
This file
Path
docs/installation.rst
186 lines · 4.9 KiB
Last changed by
Merge branch '1.0-maintenance'David Lordbefore adoption3b45b82
History of this fileTake it
1.. _installation:23Installation4============56Python Version7--------------89We recommend using the latest version of Python 3. Flask supports Python 3.410and newer, Python 2.7, and PyPy.1112Dependencies13------------1415These distributions will be installed automatically when installing Flask.1617* `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.2728.. _Werkzeug: http://werkzeug.pocoo.org/29.. _Jinja: http://jinja.pocoo.org/30.. _MarkupSafe: https://pypi.org/project/MarkupSafe/31.. _ItsDangerous: https://pythonhosted.org/itsdangerous/32.. _Click: http://click.pocoo.org/3334Optional dependencies35~~~~~~~~~~~~~~~~~~~~~3637These distributions will not be installed automatically. Flask will detect and38use them if you install them.3940* `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* `python-dotenv`_ enables support for :ref:`dotenv` when running ``flask``45 commands.46* `Watchdog`_ provides a faster, more efficient reloader for the development47 server.4849.. _Blinker: https://pythonhosted.org/blinker/50.. _SimpleJSON: https://simplejson.readthedocs.io/51.. _python-dotenv: https://github.com/theskumar/python-dotenv#readme52.. _watchdog: https://pythonhosted.org/watchdog/5354Virtual environments55--------------------5657Use a virtual environment to manage the dependencies for your project, both in58development and in production.5960What problem does a virtual environment solve? The more Python projects you61have, the more likely it is that you need to work with different versions of62Python libraries, or even Python itself. Newer versions of libraries for one63project can break compatibility in another project.6465Virtual environments are independent groups of Python libraries, one for each66project. Packages installed for one project will not affect other projects or67the operating system's packages.6869Python 3 comes bundled with the :mod:`venv` module to create virtual70environments. If you're using a modern version of Python, you can continue on71to the next section.7273If you're using Python 2, see :ref:`install-install-virtualenv` first.7475.. _install-create-env:7677Create an environment78~~~~~~~~~~~~~~~~~~~~~7980Create a project folder and a :file:`venv` folder within:8182.. code-block:: sh8384 $ mkdir myproject85 $ cd myproject86 $ python3 -m venv venv8788On Windows:8990.. code-block:: bat9192 $ py -3 -m venv venv9394If you needed to install virtualenv because you are using Python 2, use95the following command instead:9697.. code-block:: sh9899 $ python2 -m virtualenv venv100101On Windows:102103.. code-block:: bat104105 > \Python27\Scripts\virtualenv.exe venv106107.. _install-activate-env:108109Activate the environment110~~~~~~~~~~~~~~~~~~~~~~~~111112Before you work on your project, activate the corresponding environment:113114.. code-block:: sh115116 $ . venv/bin/activate117118On Windows:119120.. code-block:: bat121122 > venv\Scripts\activate123124Your shell prompt will change to show the name of the activated environment.125126Install Flask127-------------128129Within the activated environment, use the following command to install Flask:130131.. code-block:: sh132133 $ pip install Flask134135Flask is now installed. Check out the :doc:`/quickstart` or go to the136:doc:`Documentation Overview </index>`.137138Living on the edge139~~~~~~~~~~~~~~~~~~140141If you want to work with the latest Flask code before it's released, install or142update the code from the master branch:143144.. code-block:: sh145146 $ pip install -U https://github.com/pallets/flask/archive/master.tar.gz147148.. _install-install-virtualenv:149150Install virtualenv151------------------152153If you are using Python 2, the venv module is not available. Instead,154install `virtualenv`_.155156On Linux, virtualenv is provided by your package manager:157158.. code-block:: sh159160 # Debian, Ubuntu161 $ sudo apt-get install python-virtualenv162163 # CentOS, Fedora164 $ sudo yum install python-virtualenv165166 # Arch167 $ sudo pacman -S python-virtualenv168169If you are on Mac OS X or Windows, download `get-pip.py`_, then:170171.. code-block:: sh172173 $ sudo python2 Downloads/get-pip.py174 $ sudo python2 -m pip install virtualenv175176On Windows, as an administrator:177178.. code-block:: bat179180 > \Python27\python.exe Downloads\get-pip.py181 > \Python27\python.exe -m pip install virtualenv182183Now you can return above and :ref:`install-create-env`.184185.. _virtualenv: https://virtualenv.pypa.io/186.. _get-pip.py: https://bootstrap.pypa.io/get-pip.py