From 5b87b9c5e1846b698de68456c042a6d5c2e3b719 Mon Sep 17 00:00:00 2001 From: Menno Liefstingh Date: Tue, 13 Aug 2024 18:31:33 +0200 Subject: [PATCH 1/2] Check if pip is installed when not using uv flag (zenml-io#2929) --- src/zenml/cli/integration.py | 21 ++++++++++++++++++--- src/zenml/cli/utils.py | 13 +++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/zenml/cli/integration.py b/src/zenml/cli/integration.py index b8a68e92e0a..892f120b334 100644 --- a/src/zenml/cli/integration.py +++ b/src/zenml/cli/integration.py @@ -251,7 +251,7 @@ def install( force: Force the installation of the required packages. uv: Use uv for package installation (experimental). """ - from zenml.cli.utils import is_uv_installed + from zenml.cli.utils import is_pip_installed, is_uv_installed from zenml.integrations.registry import integration_registry if uv and not is_uv_installed(): @@ -259,6 +259,11 @@ def install( "UV is not installed but the uv flag was passed in. Please install uv or remove the uv flag." ) + if not uv and not is_pip_installed(): + error( + "Pip is not installed. Please install pip or use the uv flag for package installation." + ) + if not integrations: # no integrations specified, use all registered integrations integrations = set(integration_registry.integrations.keys()) @@ -346,12 +351,17 @@ def uninstall( force: Force the uninstallation of the required packages. uv: Use uv for package uninstallation (experimental). """ - from zenml.cli.utils import is_uv_installed + from zenml.cli.utils import is_pip_installed, is_uv_installed from zenml.integrations.registry import integration_registry if uv and not is_uv_installed(): error("Package `uv` is not installed. Please install it and retry.") + if not uv and not is_pip_installed(): + error( + "Pip is not installed. Please install pip or use the uv flag (--uv) for package installation." + ) + if not integrations: # no integrations specified, use all registered integrations integrations = tuple(integration_registry.integrations.keys()) @@ -423,12 +433,17 @@ def upgrade( force: Force the installation of the required packages. uv: Use uv for package installation (experimental). """ - from zenml.cli.utils import is_uv_installed + from zenml.cli.utils import is_pip_installed, is_uv_installed from zenml.integrations.registry import integration_registry if uv and not is_uv_installed(): error("Package `uv` is not installed. Please install it and retry.") + if not uv and not is_pip_installed(): + error( + "Pip is not installed. Please install pip or use the uv flag (--uv) for package installation." + ) + if not integrations: # no integrations specified, use all registered integrations integrations = set(integration_registry.integrations.keys()) diff --git a/src/zenml/cli/utils.py b/src/zenml/cli/utils.py index 27fb0e4589f..c0679853fe4 100644 --- a/src/zenml/cli/utils.py +++ b/src/zenml/cli/utils.py @@ -1169,6 +1169,19 @@ def is_uv_installed() -> bool: return False +def is_pip_installed() -> bool: + """Check if pip is installed in the current environment. + + Returns: + True if pip is installed, False otherwise. + """ + try: + pkg_resources.get_distribution("pip") + return True + except pkg_resources.DistributionNotFound: + return False + + def pretty_print_secret( secret: Dict[str, str], hide_secret: bool = True, From 1a3e28ef7c39fe11b27956831342fee395bc829a Mon Sep 17 00:00:00 2001 From: Menno Liefstingh <91878071+mennoliefstingh@users.noreply.github.com> Date: Sat, 17 Aug 2024 12:00:57 +0200 Subject: [PATCH 2/2] fix: Include --uv flag hint more explicitly in error message Co-authored-by: Alex Strick van Linschoten --- src/zenml/cli/integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zenml/cli/integration.py b/src/zenml/cli/integration.py index 892f120b334..f0d0bbfa46a 100644 --- a/src/zenml/cli/integration.py +++ b/src/zenml/cli/integration.py @@ -261,7 +261,7 @@ def install( if not uv and not is_pip_installed(): error( - "Pip is not installed. Please install pip or use the uv flag for package installation." + "Pip is not installed. Please install pip or use the uv flag (--uv) for package installation." ) if not integrations: