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.
OS: macOS 10.15 Catalina Shell: Fish
pip install poetry
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"
Execute the following to build the virtual environment, create the poetry.lock
file, and start the virtual environment.
poetry shell
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
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