Package Management with Poetry#

Update:

2024-01-03

Virtual Environment and Package Management Tool

Official site

Installation#

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

Installation steps from the official documentation.

Hint

Installation using pipx is now recommended. If you are using Windows and installed using Powershell commands, we recommend switching to management using pipx.

Basic Commands#

Check Version:

poetry –version

Creating pyproject.toml:

poetry init

install PKG:

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

Setting in-project to True will manage it within the scope of the relevant project.

Checking and configuring config for isolating venv environment:

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

History of poetry self update#

In the Windows version, self update often fails. It seems that improvements can be expected with the pipx version. The following is a memo of past workarounds from the days when installation was done using Powershell commands.

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 exists, so delete this folder

Error

FileNotFoundError: [WinError 3] The specified path was not found. : ‘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