Poetry
python
tool
CLI
package manager
virtual environments
Poetry is a package builder, dependency and virtual environment manager for python.
Installation
conda install -c conda-forge poetry
Alternatvie installation instructions: python-poetry.org
Basic usage
Set-up project
poetry new "my_project_name"
Installs poetry virtual environment and sets up the required files for poetry to work. pyproject.toml
contains the configuration for poetry and the needed dependencies. The new folder is there for your source code.
- Adding / installing single dependencies
-
Uses pip to install the new package to your virtual environment and adds it to your dependencies list.
poetry add package_name
- Installing the dependencies from the .toml-file
-
poetry install
Running code with poetry
There are two options:
- Using poetry command
-
poetry run python your_script.py
- Activating the poetry shell
-
poetry shell
Using Jupyter-Notebooks in VS-Code
- List the directory of your python interpreter:
poetry env info --path
In python-file,
on bottom right of VS-Code window click on python-version.
In new dialogue “Select Interpreter”, click “+ Enter interpreter path”
Paste the interpreter path into the text-box.
In jupyter-notebook,
Select kernel
Select Python environment
Select the python interpreter that you just listed before.
Build and publish your package
- Build package
-
This will package your file as sdist and wheel format.
poetry build
- Publish to PyPI
-
poetry publish