Pip Operations

Manage pip (python) packages. Compatible globally or inside a virtualenv (virtual environment).

Facts used in these operations: files.File, pip.PipPackages.

pip.packages

Install/remove/update pip packages.

pip.packages(
    packages: str | list[str] | None=None, present=True, latest=False,
    requirements: str | None=None, pip="pip", virtualenv: str | None=None,
    virtualenv_kwargs: dict | None=None, extra_install_args: str | None=None, **kwargs,
)

packages**: list of packages to ensure present**: whether the packages should be installed latest**: whether to upgrade packages without a specified version requirements**: location of requirements file to install/uninstall pip**: name or path of the pip directory to use virtualenv**: root directory of virtualenv to work in virtualenv_kwargs**: dictionary of arguments to pass to pip.virtualenv extra_install_args**: additional arguments to the pip install command

ualenv: This will be created if it does not exist already. virtualenv_kwargs will be passed to pip.virtualenv which can be used to control how the env is created.

ions: Package versions can be pinned like pip: <pkg>==<version>.

ample:**

ode:: python

pip.packages(

name=”Install pyinfra into a virtualenv”, packages=[“pyinfra”], virtualenv=”/usr/local/bin/venv”,

) Note:

This operation also inherits all global arguments.

pip.venv

Add/remove Python virtualenvs.

pip.venv(
    path: str, python: str | None=None, site_packages=False, always_copy=False, present=True,
    **kwargs,
)

python**: python interpreter to use site_packages**: give access to the global site-packages always_copy**: always copy files rather than symlinking present**: whether the virtualenv should exist

ample:**

ode:: python

pip.venv(

name=”Create a virtualenv”, path=”/usr/local/bin/venv”,

) Note:

This operation also inherits all global arguments.

pip.virtualenv

Add/remove Python virtualenvs.

pip.virtualenv(
    path: str, python: str | None=None, venv=False, site_packages=False, always_copy=False,
    present=True, **kwargs,
)

python**: python interpreter to use venv**: use standard venv module instead of virtualenv site_packages**: give access to the global site-packages always_copy**: always copy files rather than symlinking present**: whether the virtualenv should exist

ample:**

ode:: python

pip.virtualenv(

name=”Create a virtualenv”, path=”/usr/local/bin/venv”,

) Note:

This operation also inherits all global arguments.