[PYTHON] Poetry-An alternative to Pipenv

I used to use something called Pipenv to create a Python environment. In terms of node, it's like npm. I got a complaint that this was too slow, so I was looking for a different one, and when I searched, I found that Poetry https://python-poetry.org/ was relatively major, so I will use it.

Poetry is a mechanism that makes it easy to prepare the libraries needed for a Python project. Create a closed environment so that it will not be mixed with other Python projects, and install the library in it. Another mechanism called pyenv https://github.com/pyenv/pyenv is used to select the executable file of Python itself. Compared to Node's NPM:

How to get started

Poetry installation

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python

After installing Poetry, add $ HOME / .poetry / bin to the path.

Update of poetry itself

poetry self update

pyenv installation

brew install pyenv

Select the Python version with pyenv

Check the installable version

pyenv install --list

Install 3.7.7

pyenv install 3.7.7

Use 3.7.7 for this directory.

pyenv local 3.7.7

Make a project

When you want to create a sample project (a new folder named my-package will be created)

poetry new my-package

When you want to create a project while answering questions (create a project in the current folder)

poetry init

Manage the project

Add packages to use at runtime

poetry add (package)

Add packages to use during development

poetry add -D (package)

Install the library based on pyproject.toml or poetry.lock. Install for dev by default.

poetry install

Update the library by looking only at pyproject.toml

poetry update

Delete environment

poetry env remove 3.7.7

Migrating from Pipenv to Poetry

I migrated by poetry add while looking at the Chibi Chibi Pipfile. I edited pyproject.toml directly after poetry init to describe the required packages, but the subsequent poetry install never finished.

After that, when I did poetry add one by one, I found that it stopped with poetry add -D awscli. I don't know if it's a Poetry issue or an awscli issue, but I wasted a lot of time.

Also, Poetry doesn't have a function as a task runner (https://github.com/python-poetry/poetry/pull/591#issuecomment-504762152 is hopeless in the future), so a working script Had to switch to Makefile launch.

My impression of using Poetry is that poetry install was rather slower than pipenv install, but the others are faster, so I'm pretty happy with it.

Recommended Posts

Poetry-An alternative to Pipenv
Alternative to django's dumpdata command
Migrate from requirements.txt to pipenv
Pipenv
An alternative to `pause` in Python
Use Ghost.py as an alternative to PhantomJS