Package Management with Poetry#

Update:

2024-01-03

Virtual Environment and Package Management Tool

公式サイト

Installation#

Execute the installation command from the terminal by following the steps mentioned in the official website.

Installation steps from the official documentation.

Hint

pipx でのインストールが推奨に切り替わりました。 Windowsの方でPowershellコマンドでインストールして来た方、pipxでの管理への切替をおすすめします。

Basic Commands#

Check Version:

poetry –version

Creating pyproject.toml:

poetry init

PKGをinstall:

poetry install

Updating dependent packages:

poetry update

Adding packages:

poetry add [pkg]

Adding packages for development:

poetry add –dev [pkg]

Adding packages from GITHUB:

poetry add git+https://github.com/repo/pkg.git

Deleting packages:

poetry remove [pkg]

venv configuration#

Confirming settings:

poetry config –list

venv Separation Configuration:

poetry config virtualenvs.in-project true

in-projectはTrueにしておくと該当プロジェクトに閉じた影響範囲で管理されます。–localオプションをつけると、poetry.tomlに記録されてgit管理できるようになります。

Checking and configuring config for isolating venv environment:

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

History of poetry self update#

Windows版では、度々self updateがNGになります。pipx版になったことで改善が期待できそうです。 以下は、Powershellコマンドでインストールしていた時代の過去の対処法のメモです。

Environment

Windows 10 Pro 20H2
Python 3.9.7

1.1.6⇒1.1.7(2021/08/14)#

Error

ModuleNotFoundError: No module named ‘msgpack.exceptions’

Hint

Update Procedur
  • Delete the %USERPROFILE%.poetry folder

  • Execute recommended installation steps

(Invoke-WebRequest -Uri https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py -UseBasicParsing).Content | python -

1.1.7⇒1.1.8(2021/08/22)#

Error

ModuleNotFoundError: No module named ‘crashtest.inspector’

Hint

Recovery with the same update procedure as last time

Note

Waiting for issue fix.

1.1.8⇒1.1.9(2021/09/19)#

Hint

Recovery with the same update procedure as last time

1.1.9⇒1.1.11(2021/11/2)#

Error

$ ModuleNotFoundError: No module named ‘cleo’

Hint

Recovery with the same update procedure as last time

Hint

2021-12-18
Windows版 Python3.10.1
It seems that some of the dependencies for poetry are missing. Use the following command as a temporary measure.
> pip install cleo tomlkit poetry.core requests cachecontrol cachy html5lib pkginfo virtualenv lockfile

1.1.13(2022/3/7)#

Hint

Reinstall due to malfunction
Recovery with the same update procedure as last time

1.4.2(2023/05/03)#

Environment

Windows 11 Pro 22H2
Python 3.11.3

Hint

%USERPROFILE%.poetry does not exist and needs to be created using the conventional method.
%APPDATA%pypoetry が存在するのでこのフォルダを削除する

Error

FileNotFoundError: [WinError 3] 指定されたパスが見つかりません。: ‘C:\Users\username\AppData\Roaming\Python\Scripts\poetry.exe’

Hint

This error occurred again. Please manually delete the corresponding file and try again.
Successful installation after retrying
Finally, add to the PATH environment variable: C:UsersusernameAppDataRoamingPythonScripts