Analytics Vidhya
Published in

Analytics Vidhya

Python packaging and dependency management using poetry




On Linux/macOS

curl -sSL | python

On windows (PowerShell)

(Invoke-WebRequest -Uri -UseBasicParsing).Content | python
Retrieving Poetry metadata# Welcome to Poetry!This will download and install the latest version of Poetry,
a dependency and package manager for Python.
It will add the `poetry` command to Poetry’s bin directory, located at:$HOME/.poetry/binThis path will then be added to your `PATH` environment variable by
modifying the profile file located at:
$HOME/.profileYou can uninstall at any time by executing this script with the — uninstall option,
and these changes will be reverted.
Installing version: 1.0.5
— Downloading poetry-1.0.5-linux.tar.gz (23.00MB)
Poetry (1.0.5) is installed now. Great!To get started you need Poetry's bin directory ($HOME/.poetry/bin) in your `PATH`
environment variable. Next time you log in this will be done
To configure your current shell run `source $HOME/.poetry/env`


Install dependencies and create virtual environment

[tool.poetry]name = "test-package"version = "0.1.0"description = "The description of the package goes here"license = "MIT"authors = ["MehrdadEP <>"]readme = ''  # Markdown files are supportedrepository = ""homepage = ""keywords = ['packaging', 'poetry']
[tool.poetry.dependencies]python = "~2.7 || ^3.2" # Compatible python versions must be declared here# Dependencies with extrasrequests = { version = "^2.13", extras = [ "security" ] }# Python specific dependencies with prereleases allowedpathlib2 = { version = "^2.2", python = "~2.7", allow-prereleases = true }# Git dependenciescleo = { git = "", branch = "master" }
# Optional dependencies (extras)pendulum = { version = "^1.4", optional = true }
[]pytest = "^3.0"pytest-cov = "^2.4"
poetry install

Other useful commands

  1. Add a new dependency to your existing environment using add command
poetry add pendulum
poetry build
poetry publish
poetry show --tree
poetry show --latest
poetry new test-project
poetry shell

Uninstalling poetry

python --uninstall



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store