Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and manages them for you. It's designed to simplify package management and deployment of Python projects.
To get started with Poetry, you need to install it. You can do this via curl
or pip
.
curl
:curl -sSL https://install.python-poetry.org | python3 -
pip
(for newer Python versions):pip install poetry
To start a new project using Poetry, you can either create a new directory or initialize Poetry in an existing directory.
poetry new project-name
cd project-name
poetry init
Poetry can automatically create a virtual environment for your project to keep dependencies isolated. To configure this:
To create the virtual environment inside your project's directory, use:
poetry config virtualenvs.in-project true
Specify the Python version for the virtual environment:
poetry env use /path/to/preferred/python/version
To activate the virtual environment created by Poetry:
poetry shell
Poetry makes it easy to add, remove, and list packages required for your project.
To add a package to your project:
poetry add package-name
To remove a package from your project:
poetry remove example-package
To get a list of all the packages installed in the virtual environment:
poetry show
Poetry is a powerful tool for managing dependencies and streamlining the deployment process in Python projects. By handling package management and virtual environments, it allows developers to focus more on development and less on setup and configuration. With the above commands, you can easily manage your Python projects and ensure consistent environments across development and production setups.