install.rst
This file
Path
docs/tutorial/install.rst
116 lines · 3.6 KiB
Last changed by
Merge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727
History of this fileTake it
The walk stopped after 200 commits: lines older than 9ddef01 point at it.
Merge pull request #3955 from pallets/dependabot/pip/urllib3-1.26.4dependabot-preview[bot]before adoption9ddef01
lines 1–69why, one step back1Make 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.69Merge branch '2.1.x'David Lordbefore adoption9e2e1de
lines 70–71why, one step back70See the official `Packaging tutorial <packaging tutorial_>`_ and71`detailed guide <packaging guide_>`_ for more explanation of the filesMerge pull request #3955 from pallets/dependabot/pip/urllib3-1.26.4dependabot-preview[bot]before adoption9ddef01
lines 72–73why, one step back72and options used.73Merge branch '2.1.x'David Lordbefore adoption9e2e1de
lines 74–75why, one step back74.. _packaging tutorial: https://packaging.python.org/tutorials/packaging-projects/75.. _packaging guide: https://packaging.python.org/guides/distributing-packages-using-setuptools/Merge pull request #3955 from pallets/dependabot/pip/urllib3-1.26.4dependabot-preview[bot]before adoption9ddef01
lines 76–111why, one step back767778Install 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.Merge pull request #4646 from pallets/cli-app-envDavid Lordbefore adoptionae54727
line 112why, one step back112``--app`` is still set to ``flaskr`` and ``flask run`` still runsMerge pull request #3955 from pallets/dependabot/pip/urllib3-1.26.4dependabot-preview[bot]before adoption9ddef01
lines 113–116why, one step back113the application, but you can call it from anywhere, not just the114``flask-tutorial`` directory.115116Continue to :doc:`tests`.