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):

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

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

[requires]
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:

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

[tool.poetry.dependencies]
python = "^3.9"
uvicorn = {version = "^0.13.4", extras = ["standard"]}

[tool.poetry.dev-dependencies]

[build-system]
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.

comments powered by Disqus