2010-04-09 07:32:39 +08:00
|
|
|
Installation
|
|
|
|
============
|
|
|
|
|
2020-04-04 02:58:16 +08:00
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
Python Version
|
|
|
|
--------------
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2024-11-01 03:28:46 +08:00
|
|
|
We recommend using the latest version of Python. Flask supports Python 3.9 and newer.
|
2021-05-12 05:44:00 +08:00
|
|
|
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
Dependencies
|
|
|
|
------------
|
2010-07-18 06:51:20 +08:00
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
These distributions will be installed automatically when installing Flask.
|
2010-05-17 07:41:57 +08:00
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
* `Werkzeug`_ implements WSGI, the standard Python interface between
|
|
|
|
applications and servers.
|
|
|
|
* `Jinja`_ is a template language that renders the pages your application
|
|
|
|
serves.
|
|
|
|
* `MarkupSafe`_ comes with Jinja. It escapes untrusted input when rendering
|
|
|
|
templates to avoid injection attacks.
|
|
|
|
* `ItsDangerous`_ securely signs data to ensure its integrity. This is used
|
|
|
|
to protect Flask's session cookie.
|
|
|
|
* `Click`_ is a framework for writing command line applications. It provides
|
|
|
|
the ``flask`` command and allows adding custom management commands.
|
2023-04-13 22:34:14 +08:00
|
|
|
* `Blinker`_ provides support for :doc:`signals`.
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2019-06-24 06:37:51 +08:00
|
|
|
.. _Werkzeug: https://palletsprojects.com/p/werkzeug/
|
|
|
|
.. _Jinja: https://palletsprojects.com/p/jinja/
|
|
|
|
.. _MarkupSafe: https://palletsprojects.com/p/markupsafe/
|
|
|
|
.. _ItsDangerous: https://palletsprojects.com/p/itsdangerous/
|
|
|
|
.. _Click: https://palletsprojects.com/p/click/
|
2023-04-13 22:34:14 +08:00
|
|
|
.. _Blinker: https://blinker.readthedocs.io/
|
2010-06-26 14:39:16 +08:00
|
|
|
|
2020-04-04 02:58:16 +08:00
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
Optional dependencies
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
These distributions will not be installed automatically. Flask will detect and
|
|
|
|
use them if you install them.
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2017-07-15 13:37:53 +08:00
|
|
|
* `python-dotenv`_ enables support for :ref:`dotenv` when running ``flask``
|
|
|
|
commands.
|
2017-10-11 02:10:20 +08:00
|
|
|
* `Watchdog`_ provides a faster, more efficient reloader for the development
|
|
|
|
server.
|
2017-03-20 01:01:23 +08:00
|
|
|
|
2017-07-15 13:37:53 +08:00
|
|
|
.. _python-dotenv: https://github.com/theskumar/python-dotenv#readme
|
2017-10-11 02:10:20 +08:00
|
|
|
.. _watchdog: https://pythonhosted.org/watchdog/
|
2017-03-20 01:01:23 +08:00
|
|
|
|
2020-04-04 02:58:16 +08:00
|
|
|
|
2021-11-12 08:12:08 +08:00
|
|
|
greenlet
|
|
|
|
~~~~~~~~
|
|
|
|
|
|
|
|
You may choose to use gevent or eventlet with your application. In this
|
|
|
|
case, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is
|
|
|
|
required.
|
|
|
|
|
|
|
|
These are not minimum supported versions, they only indicate the first
|
|
|
|
versions that added necessary features. You should use the latest
|
|
|
|
versions of each.
|
|
|
|
|
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
Virtual environments
|
|
|
|
--------------------
|
2017-03-20 01:01:23 +08:00
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
Use a virtual environment to manage the dependencies for your project, both in
|
|
|
|
development and in production.
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
What problem does a virtual environment solve? The more Python projects you
|
|
|
|
have, the more likely it is that you need to work with different versions of
|
|
|
|
Python libraries, or even Python itself. Newer versions of libraries for one
|
|
|
|
project can break compatibility in another project.
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
Virtual environments are independent groups of Python libraries, one for each
|
|
|
|
project. Packages installed for one project will not affect other projects or
|
|
|
|
the operating system's packages.
|
2010-06-26 14:39:16 +08:00
|
|
|
|
2020-04-04 02:58:16 +08:00
|
|
|
Python comes bundled with the :mod:`venv` module to create virtual
|
|
|
|
environments.
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2017-03-20 01:01:23 +08:00
|
|
|
|
2020-04-05 03:57:14 +08:00
|
|
|
.. _install-create-env:
|
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
Create an environment
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2023-01-19 02:21:37 +08:00
|
|
|
Create a project folder and a :file:`.venv` folder within:
|
2017-03-20 01:01:23 +08:00
|
|
|
|
2020-10-16 05:08:37 +08:00
|
|
|
.. tabs::
|
|
|
|
|
|
|
|
.. group-tab:: macOS/Linux
|
|
|
|
|
|
|
|
.. code-block:: text
|
2017-03-20 01:01:23 +08:00
|
|
|
|
2020-10-16 05:08:37 +08:00
|
|
|
$ mkdir myproject
|
|
|
|
$ cd myproject
|
2023-01-19 02:21:37 +08:00
|
|
|
$ python3 -m venv .venv
|
2017-03-20 01:01:23 +08:00
|
|
|
|
2020-10-16 05:08:37 +08:00
|
|
|
.. group-tab:: Windows
|
2017-03-20 01:01:23 +08:00
|
|
|
|
2020-10-16 05:08:37 +08:00
|
|
|
.. code-block:: text
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2020-10-16 05:08:37 +08:00
|
|
|
> mkdir myproject
|
|
|
|
> cd myproject
|
2023-01-19 02:21:37 +08:00
|
|
|
> py -3 -m venv .venv
|
2017-03-20 01:01:23 +08:00
|
|
|
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2018-02-10 06:39:05 +08:00
|
|
|
.. _install-activate-env:
|
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
Activate the environment
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
Before you work on your project, activate the corresponding environment:
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2020-10-16 05:08:37 +08:00
|
|
|
.. tabs::
|
|
|
|
|
|
|
|
.. group-tab:: macOS/Linux
|
|
|
|
|
|
|
|
.. code-block:: text
|
2014-06-16 18:39:16 +08:00
|
|
|
|
2023-01-19 02:21:37 +08:00
|
|
|
$ . .venv/bin/activate
|
2014-06-16 18:39:16 +08:00
|
|
|
|
2020-10-16 05:08:37 +08:00
|
|
|
.. group-tab:: Windows
|
2014-06-16 18:39:16 +08:00
|
|
|
|
2020-10-16 05:08:37 +08:00
|
|
|
.. code-block:: text
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2023-01-19 02:21:37 +08:00
|
|
|
> .venv\Scripts\activate
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2020-04-04 02:58:16 +08:00
|
|
|
Your shell prompt will change to show the name of the activated
|
|
|
|
environment.
|
|
|
|
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
Install Flask
|
|
|
|
-------------
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2020-04-04 02:58:16 +08:00
|
|
|
Within the activated environment, use the following command to install
|
|
|
|
Flask:
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2017-05-12 04:54:37 +08:00
|
|
|
.. code-block:: sh
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2018-09-09 16:41:56 +08:00
|
|
|
$ pip install Flask
|
2010-04-09 19:13:39 +08:00
|
|
|
|
2018-05-09 11:10:27 +08:00
|
|
|
Flask is now installed. Check out the :doc:`/quickstart` or go to the
|
|
|
|
:doc:`Documentation Overview </index>`.
|