A Python library
What is Poetry?
- A python library helps you declare, manage and install dependencies of Python projects, ensuring you have the right stack everywhere.
- It will have all the libraries with there version so that same code will work for others without single change.
How to install poetry?
- First install poetry by using.
curl -sSL https://install.python-poetry.org | python3 -
- Check poetry is installed using.
poetry - version
How to create a new project using poetry?
- To create a new project using poetry is very simple.
poetry new project_name
NOTE: After that it will ask you about other details and for demo just hit enter for all the details.
How to initialise poetry in pre-existing project?
To use poetry in pre-existing project use.
poetry init
How to add new library dependency in poetry?
To add new library into poetry is very simple use.
poetry add library_name
For example: I want to add pandas.
poetry add pandas
How to activate virtual environment?
To activate virtual environment use command:
poetry shell
To deactivate virtual environment use command:
exit
How to install defined dependency?
To install defined dependency use command:
poetry install
How to update dependency?
To update dependency use command:
poetry update
How to update lock file?
To update lock file use command:
poetry lock -no-update
Whenever new library is added make sure to use “poetry lock” command so that pyproject.toml file also gets updated else it will cause issues when you install library using “poetry install”.
Saying that there is difference in poetry.lock and pyproject.toml file.
Youtube video link.