Skip to content
Myr

install.rst

This file

Path

docs/tutorial/install.rst

113 lines · 3.4 KiB

Last changed by

Merge pull request #2676 from davidism/tutorialDavid Lordbefore adoptionc3e2ff2

History of this file

Take it

1Make the Project Installable2============================34Making your project installable means that you can build a5*distribution* file and install that in another environment, just like6you installed Flask in your project's environment. This makes deploying7your project the same as installing any other library, so you're using8all the standard Python tools to manage everything.910Installing also comes with other benefits that might not be obvious from11the tutorial or as a new Python user, including:1213*   Currently, Python and Flask understand how to use the ``flaskr``14    package only because you're running from your project's directory.15    Installing means you can import it no matter where you run from.1617*   You can manage your project's dependencies just like other packages18    do, so ``pip install yourproject.whl`` installs them.1920*   Test tools can isolate your test environment from your development21    environment.2223.. note::24    This is being introduced late in the tutorial, but in your future25    projects you should always start with this.262728Describe the Project29--------------------3031The ``setup.py`` file describes your project and the files that belong32to it.3334.. code-block:: python35    :caption: ``setup.py``3637    from setuptools import find_packages, setup3839    setup(40        name='flaskr',41        version='1.0.0',42        packages=find_packages(),43        include_package_data=True,44        zip_safe=False,45        install_requires=[46            'flask',47        ],48    )495051``packages`` tells Python what package directories (and the Python files52they contain) to include. ``find_packages()`` finds these directories53automatically so you don't have to type them out. To include other54files, such as the static and templates directories,55``include_package_data`` is set. Python needs another file named56``MANIFEST.in`` to tell what this other data is.5758.. code-block:: none59    :caption: ``MANIFEST.in``6061    include flaskr/schema.sql62    graft flaskr/static63    graft flaskr/templates64    global-exclude *.pyc6566This tells Python to copy everything in the ``static`` and ``templates``67directories, and the ``schema.sql`` file, but to exclude all bytecode68files.6970See the `official packaging guide`_ for another explanation of the files71and options used.7273.. _official packaging guide: https://packaging.python.org/tutorials/distributing-packages/747576Install the Project77-------------------7879Use ``pip`` to install your project in the virtual environment.8081.. code-block:: none8283    pip install -e .8485This tells pip to find ``setup.py`` in the current directory and install86it in *editable* or *development* mode. Editable mode means that as you87make changes to your local code, you'll only need to re-install if you88change the metadata about the project, such as its dependencies.8990You can observe that the project is now installed with ``pip list``.9192.. code-block:: none9394    pip list9596    Package        Version   Location97    -------------- --------- ----------------------------------98    click          6.799    Flask          1.0100    flaskr         1.0.0     /home/user/Projects/flask-tutorial101    itsdangerous   0.24102    Jinja2         2.10103    MarkupSafe     1.0104    pip            9.0.3105    setuptools     39.0.1106    Werkzeug       0.14.1107    wheel          0.30.0108109Nothing changes from how you've been running your project so far.110``FLASK_APP`` is still set to ``flaskr`` and ``flask run`` still runs111the application.112113Continue to :doc:`tests`.