Skip to content
Myr

install.rst

This file

Path

docs/tutorial/install.rst

107 lines · 3.3 KiB

Last changed by

Merge pull request #4947 from pallets/pyprojectDavid Lordbefore adoption78b42b9

History of this file

Take it

1Make the Project Installable2============================34Making your project installable means that you can build a *wheel* file and install that5in another environment, just like you installed Flask in your project's environment.6This makes deploying your project the same as installing any other library, so you're7using all the standard Python tools to manage everything.89Installing also comes with other benefits that might not be obvious from10the tutorial or as a new Python user, including:1112*   Currently, Python and Flask understand how to use the ``flaskr``13    package only because you're running from your project's directory.14    Installing means you can import it no matter where you run from.1516*   You can manage your project's dependencies just like other packages17    do, so ``pip install yourproject.whl`` installs them.1819*   Test tools can isolate your test environment from your development20    environment.2122.. note::23    This is being introduced late in the tutorial, but in your future24    projects you should always start with this.252627Describe the Project28--------------------2930The ``pyproject.toml`` file describes your project and how to build it.3132.. code-block:: toml33    :caption: ``pyproject.toml``3435    [project]36    name = "flaskr"37    version = "1.0.0"38    dependencies = [39        "flask",40    ]4142    [build-system]43    requires = ["setuptools"]44    build-backend = "setuptools.build_meta"454647The setuptools build backend needs another file named ``MANIFEST.in`` to tell it about48non-Python files to include.4950.. code-block:: none51    :caption: ``MANIFEST.in``5253    include flaskr/schema.sql54    graft flaskr/static55    graft flaskr/templates56    global-exclude *.pyc5758This tells the build to copy everything in the ``static`` and ``templates`` directories,59and the ``schema.sql`` file, but to exclude all bytecode files.6061See the official `Packaging tutorial <packaging tutorial_>`_ and62`detailed guide <packaging guide_>`_ for more explanation of the files63and options used.6465.. _packaging tutorial: https://packaging.python.org/tutorials/packaging-projects/66.. _packaging guide: https://packaging.python.org/guides/distributing-packages-using-setuptools/676869Install the Project70-------------------7172Use ``pip`` to install your project in the virtual environment.7374.. code-block:: none7576    $ pip install -e .7778This tells pip to find ``pyproject.toml`` in the current directory and install the79project in *editable* or *development* mode. Editable mode means that as you make80changes to your local code, you'll only need to re-install if you change the metadata81about the project, such as its dependencies.8283You can observe that the project is now installed with ``pip list``.8485.. code-block:: none8687    $ pip list8889    Package        Version   Location90    -------------- --------- ----------------------------------91    click          6.792    Flask          1.093    flaskr         1.0.0     /home/user/Projects/flask-tutorial94    itsdangerous   0.2495    Jinja2         2.1096    MarkupSafe     1.097    pip            9.0.398    setuptools     39.0.199    Werkzeug       0.14.1100    wheel          0.30.0101102Nothing changes from how you've been running your project so far.103``--app`` is still set to ``flaskr`` and ``flask run`` still runs104the application, but you can call it from anywhere, not just the105``flask-tutorial`` directory.106107Continue to :doc:`tests`.