Benefits of Making Your Project Installable
Installing comes with several benefits:-
Import from anywhere - Python and Flask can use the
flaskrpackage no matter where you run from, not just from your project’s directory -
Dependency management - You can manage your project’s dependencies just like other packages do, so
pip install yourproject.whlinstalls them - Test isolation - Test tools can isolate your test environment from your development environment
This is being introduced late in the tutorial, but in your future projects you should always start with this.
Describe the Project
Create pyproject.toml
The Configuration breakdown:
pyproject.toml file describes your project and how to build it.Create pyproject.toml in the project root:pyproject.toml
name- The package name that will be used when installingversion- The current version of your applicationdescription- A brief description of what your application doesdependencies- List of packages your project needs (Flask in this case)build-system- Specifies how to build the distribution file
Install the Project
Install in editable mode
Use This tells pip to find
pip to install your project in the virtual environment:pyproject.toml in the current directory and install the project in editable or development mode.Editable mode means that as you make changes to your local code, you’ll only need to re-install if you change the metadata about the project, such as its dependencies.Running the Application
Nothing changes from how you’ve been running your project so far:flask-tutorial directory.
Building a Distribution File
When you want to deploy your application elsewhere, you build a wheel (.whl) file:
The file name format is:
Installing on Another Machine
Instance Folder Location
When Flask detects that it’s installed (not in editable mode), it uses a different directory for the instance folder:- Development (editable):
flask-tutorial/instance/ - Installed:
.venv/var/flaskr-instance/
Project Structure Summary
Your final installable project structure:Now your application is properly packaged and can be installed on any system with Python. The next step is to add comprehensive tests.
