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
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
Hint
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
Hint
Note
1.1.8⇒1.1.9(2021/09/19)#
Hint
1.1.9⇒1.1.11(2021/11/2)#
Error
$ ModuleNotFoundError: No module named ‘cleo’
Hint
Hint
1.1.13(2022/3/7)#
Hint
1.4.2(2023/05/03)#
Environment
Windows 11 Pro 22H2
Python 3.11.3
Hint
Error
FileNotFoundError: [WinError 3] The specified path was not found. : ‘C:\Users\username\AppData\Roaming\Python\Scripts\poetry.exe’
Hint