Manage Python runtime packages and development environment packages with Poetry

Using Poetry to manage PyPI packages seemed to be more convenient than using requirements.txt in the following ways:

--You can manage packages used in development / production environment separately (like npm devdependencies) --You can manage only the packages that the product directly depends on. --The version of the package that depends on the dependent package is managed by poetry.lock, and the version of the dependent package does not go up and get stuck (like npm, package-lock.json, yarn.lock). ) --You can upgrade the version of dependent packages with one command. --virtualenv.in-project If true is set, venv will be used to install the package in the .venv directory (it is convenient because the .venv directory is automatically recognized by VS Code).

I have summarized the commands that I think I will use.

Poetry installation

pip install --user poetry

Use venv, which is used to separate the environment, and set the .venv directory to be created and used automatically.

poetry config virtualenvs.in-project true

Install packages for development only

poetry add -D black

Installing dependent packages from the application

poetry add flask

When building a development environment on another machine

#Creating a separate environment
python -m venv .venv

#Package installation
poetry install

Program execution

The package is installed under .venv, so run it in .venv

.venv/bin/python api.py

Or run via Poetry

poetry run python api.py

Package update

poetry update

Containerization

Do not use .venv in the container, use Poetry's environment isolation function (because it is not shared with VSCode and does not need to be a .venv directory in particular)

FROM python:3.8.2

#Poetry installation
RUN pip install poetry==1.0.5

WORKDIR /app

#Installation of dependent packages
COPY poetry.lock pyproject.toml ./
#except dev
RUN poetry install --no-dev

#Application storage
COPY api.py ./
# ...

#Run via Poetry
CMD ["poetry", "run", "python", "api.py"]

Recommended Posts

Manage Python runtime packages and development environment packages with Poetry
Get a quick Python development environment with Poetry
Manage python environment with virtualenv
[Package cloud] Manage python packages with package cloud
Prepare Python development environment with Atom
Unify the environment of the Python development team starting with Poetry
Get a clean Python development environment with pyenv + pipx + Poetry
[Development environment] Python with Xcode [With screen transition]
Python virtual environment and packages on Ubuntu
Clean python environment with pythonz and virtualenv
Create a simple Python development environment with VS Code and Docker
Windows + gVim + Poetry python development environment construction
Recommended environment and usage when developing with Python
Building a python environment with virtualenv and direnv
Build Python development environment with Visual Studio Code
Python development flow using Poetry, Git and Docker
Declaratively manage your environment with Nix and home-manager
Manage Python multiple version environment with Pythonz, virtualenv
[Python] Build a Django development environment with Docker
Continuation of multi-platform development with Electron and Python
Build PyPy and Python execution environment with Docker
Python packages and modules
Python development environment construction
About Python development environment
Python environment with docker-compose
python2.7 development environment construction
Development environment in Python
Virtual environment with Python 3.6
Virtualize (isolate) IBM i python development environment with chroot
Build a python virtual environment with virtualenv and virtualenvwrapper
Create a python development environment with vagrant + ansible + fabric
Build a machine learning application development environment with Python
Python development environment with Windows + Anaconda3 + Visual Studio Code
Read and write files with Slackbot ~ Bot development with Python ~
QGIS3 Python plugin development environment construction with VSCode (macOS)
Python development environment with Windows + Python + PipEnv + Visual Studio Code
Install Ubuntu 20.04 with GUI and prepare the development environment
python package dependencies and virtual environment management tool Poetry
Build a development environment with Poetry Django Docker Pycharm
Set up a Python development environment with Sublime Text 2
[Python] Chapter 01-02 About Python (Execution and installation of development environment)
Encryption and decryption with Python
Python and hardware-Using RS232C with Python-
Install Python environment with Anaconda
Understand Python packages and modules
Build python3 environment with ubuntu 16.04
Prepare python3 environment with Docker
Build python environment with direnv
Organize your Python development environment
Python environment construction and TensorFlow
[ev3dev × Python] Build ev3dev development environment
[MEMO] [Development environment construction] Python
[For organizing] Python development environment
python with pyenv and venv
Works with Python and R
Set up a Python development environment with Visual Studio Code
Video cannot be loaded with Spyder in Python development environment
Prepare Python development environment with Mac + Windows + VisualStudio Code (Windows version)
Prepare Python development environment with Mac + Windows + VisualStudio Code (Mac version)
Package python runtime and pypi library with chef / omnibus and Docker
How to build a python2.7 series development environment with Vagrant