Skip to content

Instantly share code, notes, and snippets.

@1eedaegon
Last active November 6, 2024 07:09
Show Gist options
  • Save 1eedaegon/cc23648cd2f92331c3f748be9cac4f03 to your computer and use it in GitHub Desktop.
Save 1eedaegon/cc23648cd2f92331c3f748be9cac4f03 to your computer and use it in GitHub Desktop.
How to setup poetry python dependency manager

How to use poetry python dependency manager

awesome pacakage manager: poetry

Download poetry installer file and Install

First, download poetry python file

> curl -sSL https://install.python-poetry.org | python3 -

Default setting

Setting to create a virtualenv inside a project when installing a package

> poetry config virtualenvs.in-project true
> poetry config virtualenvs.path "./.venv"

Test

Test to make project

  1. Make project
> poetry new poetry-test
Created package poetry_test in poetry-test
  1. Check directory
> ls -alh poetry-test
total 20K
drwxr-xr-x 4 lee lee 4.0K Jun 14 22:00 .
drwxr-xr-x 6 lee lee 4.0K Jun 14 22:00 ..
-rw-r--r-- 1 lee lee    0 Jun 14 22:00 README.rst
drwxr-xr-x 2 lee lee 4.0K Jun 14 22:00 poetry_test
-rw-r--r-- 1 lee lee  299 Jun 14 22:00 pyproject.toml
drwxr-xr-x 2 lee lee 4.0K Jun 14 22:00 tests
  1. Initialize packages
> poetry install && poetry update
Creating virtualenv poetry-test in /home/lee/workspace/python/poetry-test/.venv
Updating dependencies
Resolving dependencies... (1.0s)

Writing lock file

Package operations: 8 installs, 0 updates, 0 removals

  • Installing pyparsing (3.0.9)
  • Installing attrs (21.4.0)
  • Installing more-itertools (8.13.0)
  • Installing packaging (21.3)
  • Installing pluggy (0.13.1)
  • Installing py (1.11.0)
  • Installing wcwidth (0.2.5)
  • Installing pytest (5.4.3)

Installing the current project: poetry-test (0.1.0)
Updating dependencies
Resolving dependencies... (0.1s)

No dependencies to install or update
  1. Check the directory after installation
> ls -lah
total 32K
drwxr-xr-x 5 lee lee 4.0K Jun 14 22:04 .
drwxr-xr-x 6 lee lee 4.0K Jun 14 22:00 ..
drwxr-xr-x 4 lee lee 4.0K Jun 14 22:04 .venv
-rw-r--r-- 1 lee lee    0 Jun 14 22:00 README.rst
-rw-r--r-- 1 lee lee 5.9K Jun 14 22:04 poetry.lock
drwxr-xr-x 2 lee lee 4.0K Jun 14 22:00 poetry_test
-rw-r--r-- 1 lee lee  299 Jun 14 22:00 pyproject.toml
drwxr-xr-x 2 lee lee 4.0K Jun 14 22:00 tests

Uninstall

Remove project and clear poetry

Must be inside the project

  1. Check virtualenv
> poetry env list
.venv (Activated)
  1. Remove project
  • Manually
> poetry env remove [virtualenv name]
> cd ../ && rm -rf ./poetry-test
  • Easy way
> cd ../ && rm -rf ./poetry-test

etc

vscode auto import(settings.json)

{
  "python.venvPath": "${workspaceFolder}/.venv"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment