~ 1 min read

Installing Module Extras with Pipenv and Poetry

I thought it worth documenting how to install “extra” dependencies in Pipenv and Poetry after struggling to find the answer myself. Context: I hit a problem with uvicorn where the websockets module hadn’t been installed as a result of not including the “standard” extras. Rather than return an error, it just failed to connect the websocket which made me think something was wrong with my network configuration.

As an example, take the following pip command:

pip install uvicorn[standard]

With Pipenv, the equivalent would be to pip install a Pipfile that looks something like this (I can’t see a way to do this from Pipenvs cli):

name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

uvicorn = {extras = ["standard"], version = "*"}

python_version = "3.9.1"

In poetry the same can be done from the cli using:

poetry add uvicorn -E standard

Which will create a pyproject.toml for poetry as follows:

name = "uvicorn-test"
version = "0.1.0"
description = ""
authors = ["Ian Wootten <hi@niftydigits.com>"]

python = "^3.9"
uvicorn = {version = "^0.13.4", extras = ["standard"]}


requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

The “-E” option on the add command for poetry appears to be documented on install only.

Subscribe for Exclusives

My monthly newsletter shares exclusive articles you won't find elsewhere, tools and code. No spam, unsubscribe any time.