install.rst
This file
Path
docs/tutorial/install.rst
115 lines · 3.6 KiB
Last changed by
fix: remove obsolete `zip_safe` (#4783)Kevin Kirschebefore adoption00bdc2b
History of this fileTake 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 install_requires=[45 'flask',46 ],47 )484950``packages`` tells Python what package directories (and the Python files51they contain) to include. ``find_packages()`` finds these directories52automatically so you don't have to type them out. To include other53files, such as the static and templates directories,54``include_package_data`` is set. Python needs another file named55``MANIFEST.in`` to tell what this other data is.5657.. code-block:: none58 :caption: ``MANIFEST.in``5960 include flaskr/schema.sql61 graft flaskr/static62 graft flaskr/templates63 global-exclude *.pyc6465This tells Python to copy everything in the ``static`` and ``templates``66directories, and the ``schema.sql`` file, but to exclude all bytecode67files.6869See the official `Packaging tutorial <packaging tutorial_>`_ and70`detailed guide <packaging guide_>`_ for more explanation of the files71and options used.7273.. _packaging tutorial: https://packaging.python.org/tutorials/packaging-projects/74.. _packaging guide: https://packaging.python.org/guides/distributing-packages-using-setuptools/757677Install the Project78-------------------7980Use ``pip`` to install your project in the virtual environment.8182.. code-block:: none8384 $ pip install -e .8586This tells pip to find ``setup.py`` in the current directory and install87it in *editable* or *development* mode. Editable mode means that as you88make changes to your local code, you'll only need to re-install if you89change the metadata about the project, such as its dependencies.9091You can observe that the project is now installed with ``pip list``.9293.. code-block:: none9495 $ pip list9697 Package Version Location98 -------------- --------- ----------------------------------99 click 6.7100 Flask 1.0101 flaskr 1.0.0 /home/user/Projects/flask-tutorial102 itsdangerous 0.24103 Jinja2 2.10104 MarkupSafe 1.0105 pip 9.0.3106 setuptools 39.0.1107 Werkzeug 0.14.1108 wheel 0.30.0109110Nothing changes from how you've been running your project so far.111``--app`` is still set to ``flaskr`` and ``flask run`` still runs112the application, but you can call it from anywhere, not just the113``flask-tutorial`` directory.114115Continue to :doc:`tests`.