Python: Setting up the environment
Theory: Building a package distribution using Poetry
When your project is ready to be shared with others, it's time to build the code. The compiled distribution doesn't need Poetry anymore. The program will run without it.
It is where Poetry comes in again. In this tutorial, we'll learn how to build and install the distribution.
Building and installing the distribution kit
Usually, Poetry projects are almost ready to build their distributions. Some cases require additional configuration steps. But we won't go into that because it's irrelevant.
You can build a simple project using the poetry build command:
Run this command in the root directory of the project. You will see a dist/ directory with two files with different extensions.
First, we look at a file with the .whl extension, which is short for wheel. This file is already suitable for installation using pip. Let's install it in the user's environment:
If there are scripts described for the project, they're available as commands. For example, this is how say-hello works in our case:
Installing the package without building the distribution
When you work on code, you often want to try out your project quickly and without too much effort.
Let's try running the program without building a distribution. To do this, specify the path to the project directory as the package name in the pip install command:
In the code above, we used the dot . — if you remember, that means the current directory.
Installing Poetry projects from GitHub
This course mentioned earlier that you can install packages directly from GitHub using pip. This feature is also available for poetry projects.
Pip has only recently become aware of pyproject.toml. We recommend that you upgrade pip regularly with the pip install --user --upgrade pip command.