Using Poetry with Fish (Migration from Pipenv)

Introduction

Python Package Management Best Practices for 2020 was buzzing, so I looked it up and found that I had been interested in [Poetry](https: /). (/python-poetry.org) is pretty good, so I migrated from Pipenv.

environment

OS: macOS 10.15 Catalina Shell: Fish

Poetry installation

pip install poetry

Environment variable settings

In Pipenv, the virtual environment was set as follows so that it would be created in the project folder.

export PIPENV_VENV_IN_PROJECT=true

In Poetry, it seems that you should set as follows.

poetry config --list
poetry config virtualenvs.in-project true

Pipfile→pyproject.toml Poetry manages the library in pyproject.toml, so conversion is required. Fortunately, the conversion tool poetrify is open to the public, so I will use it (for details, see Author's Blog. See hateblo.jp/entry/2019/01/16/191452).


pip install poetrify
cd example/
poetrify generate

I tried converting the Pipfile and it worked.

Pipfile


[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
black = "==18.3a1"
mypy = "*"
pytest = "*"

[packages]
numpy = "*"
scipy = "*"
plotly = "*"
sklearn = "*"

[requires]
python_version = "3.7"

pyproject.toml


[tool.poetry]
name = "exampy"
version = "0.1.0"
description = ""
authors = ["ryoppippi <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.7"
numpy = "^1.17.4"
scipy = "^1.4.1"
plotly = "^4.4.1"
sklearn = "^0.0"

[tool.poetry.dev-dependencies]
black = "^19.10b0"
mypy = "^0.761"
pytest = "^5.3.2"

[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

Building a virtual environment

Execute the following to build the virtual environment, create the poetry.lock file, and start the virtual environment.

poetry shell

Dec-21-2019 19-44-51.gif

Plugin for Fish

I use Fish as a shell, but during the Pipenv era I used to use a plugin called fish-pipenv. This plugin was excellent because it automatically activates the virtual environment when you move to the directory of the project built with pipenv. Unfortunately, there was no equivalent for Poetry yet, so I made it myself this time. I want you to make use of it. fish-poetry Dec-21-2019 19-55-32.gif

Summary

There is no dissatisfaction with the cooperation with Pyenv being a little subtle, but there are many advantages such as overwhelmingly quick lock. I will move to Poetry one by one.

Recommended Posts

Using Poetry with Fish (Migration from Pipenv)
Using Rstan from Python with PypeR
Deploy flask app with mod_wsgi (using pipenv)
Pipenv install with ssh from Private Bitbucket Repository
The story of moving from Pipenv to Poetry
Principal component analysis using python from nim with nimpy
I tried using Pipenv
[Python] I started Poetry & Impression that I moved from Pipenv to poetry
I tried using the Python library from Ruby with PyCall
Image recognition with API from zero knowledge using AutoML Vision
I want to install a package from requirements.txt with poetry