1 분 소요


When developing with Python, you encounter various virtual environment management packages. This time, I’m going to introduce poetry, a new friend that even manages package versions.

Let’s Use Poetry

First, let’s install Poetry to use it

Installation

Poetry can be installed as a Python package or through brew, Mac’s package installer.

Installation Method - brew

brew install poetry

Installation Method - pip

pip install poetry

Package Init

To develop Python using poetry, you need to declare it in the file using the init command.

poetry init

Then, it asks various things needed for init, which you can fill in according to your Python project’s characteristics It prepares the Python development environment while asking various questions Although I filled these in, from the first screen to the last, you can just press enter and the Python development project setup will be complete. When finished, you’ll see a project environment summary like the screen below. Then the pyproject.toml file is created and the configuration is complete

How to Use Poetry - shell, add

poetry shell

Now that we’ve configured packages with poetry, let’s try using it

We’ll use the shell command to activate the virtual environment

poetry shell

Then the Python virtual environment corresponding to the package is created and activated

poetry add

To activate the virtual environment and install packages in it, you need to execute the add command

One of the reasons poetry is great is that you don’t even need to activate the virtual environment (shell) - using the add command will install packages automatically!

Let’s install Django, Flask, requests, and aiohttp which are frequently used in Python

poetry add Django Flask requests aiohttp

Normally pip would just install the latest version of the packages, but our strong friend poetry doesn’t do that It searches for the package files to download and installs them according to each package’s dependencies

pyproject.toml

After installing packages with poetry, it automatically updates which packages have been installed

댓글남기기