See the docs: Library > Metadata >
Charm libraries often need to use regular Python libraries.
However, they have a very specific structure aimed for simplicity and integration with charms and Charmhub. One of the characteristics (by design) is that they shall have only one Python file, which is a problem the moment the library needs to specify Python dependencies, as in the Python world all mechanisms implies a separate file.
charmcraft 2.2.0+89.g8a3a0e6 (currently released in the
edge channel) there is a mechanism to declare in the charm library’s unique file which dependencies are needed by that library: the
This is a new special key in the charm library (the others are
LIBPATCH). Unlike those previous keys,
PYDEPS is optional and it’s not a single value but a list of strings, each string being a regular “pip installable” Python dependency that will be normally retrieved from PyPI (but subject to user’s system configuration), and supporting all formats (just the package name, a link to a Github project, etc.).
The following are examples of possible PYDEPS declarations.
PYDEPS=["jinja2"] PYDEPS = ["pyyaml", "httpcore<0.15.0,>=0.14.5"] PYDEPS = [ "git+https://github.com/canonical/operator/#egg=ops", "httpcore<0.15.0,>=0.14.5", "requests", ]
Of course only one
PYDEPS declaration is allowed, if any.
Charmcraft will collect the dependencies from all libraries included in the charm and install them from source in the virtual environment inside the
.charm file, together with all the other Python dependencies declared by the charm itself.
pip, when called to install all the dependencies from the charm and all the used libraries, may detect conflicts between the requested packages and their versions. This is a feature, because it’s always better to detect incompatibilities between dependencies at this moment than when the charm is being deployed or run after deployment.