Skip to content
Myr

install.rst

This file

Path

docs/tutorial/install.rst

116 lines · 3.6 KiB

Last changed by

Merge branch '2.1.x'David Lordbefore adoption9e2e1de

History of this file

Take it

The walk stopped after 200 commits: lines older than 1035efc point at it.

Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc

lines 1–69why, one step back
1Make the Project Installable
2============================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.69

Merge branch '2.1.x'David Lordbefore adoption9e2e1de

lines 70–71why, one step back
70See the official `Packaging tutorial <packaging tutorial_>`_ and
71`detailed guide <packaging guide_>`_ for more explanation of the files

Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc

lines 72–73why, one step back
72and options used.
73

Merge branch '2.1.x'David Lordbefore adoption9e2e1de

lines 74–75why, one step back
74.. _packaging tutorial: https://packaging.python.org/tutorials/packaging-projects/
75.. _packaging guide: https://packaging.python.org/guides/distributing-packages-using-setuptools/

Add command switch tabs for Bash, CMD and Powershell with sphinx-tabs (#3714)Grey Libefore adoption1035efc

lines 76–116why, one step back
76
7778Install the Project79-------------------8081Use ``pip`` to install your project in the virtual environment.8283.. code-block:: none8485 $ pip install -e .8687This tells pip to find ``setup.py`` in the current directory and install88it in *editable* or *development* mode. Editable mode means that as you89make changes to your local code, you'll only need to re-install if you90change the metadata about the project, such as its dependencies.9192You can observe that the project is now installed with ``pip list``.9394.. code-block:: none9596 $ pip list9798 Package Version Location99 -------------- --------- ----------------------------------100 click 6.7101 Flask 1.0102 flaskr 1.0.0 /home/user/Projects/flask-tutorial103 itsdangerous 0.24104 Jinja2 2.10105 MarkupSafe 1.0106 pip 9.0.3107 setuptools 39.0.1108 Werkzeug 0.14.1109 wheel 0.30.0110111Nothing changes from how you've been running your project so far.112``FLASK_APP`` is still set to ``flaskr`` and ``flask run`` still runs113the application, but you can call it from anywhere, not just the114``flask-tutorial`` directory.115116Continue to :doc:`tests`.