From 3d1b5c57eaa2c2a2dbafdc56ba6280b10edac84d Mon Sep 17 00:00:00 2001 From: Eugene Brodsky Date: Tue, 6 Feb 2024 09:35:24 -0500 Subject: [PATCH] fix(installer): more reliably upgrade pip --- installer/lib/installer.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/installer/lib/installer.py b/installer/lib/installer.py index e46397ad5f..229db8b10a 100644 --- a/installer/lib/installer.py +++ b/installer/lib/installer.py @@ -73,7 +73,7 @@ class Installer: try: # upgrade pip to the latest version to avoid a confusing message - res = subprocess.check_output([pip, "install", "--upgrade", "pip"]).decode() + res = upgrade_pip(Path(venv_dir.name)) if verbose: print(res) @@ -169,6 +169,7 @@ class InvokeAiInstance: set_sys_path(venv) os.environ["INVOKEAI_ROOT"] = str(self.runtime.expanduser().resolve()) os.environ["VIRTUAL_ENV"] = str(self.venv.expanduser().resolve()) + upgrade_pip(venv) def get(self) -> tuple[Path, Path]: """ @@ -218,7 +219,6 @@ class InvokeAiInstance: from plumbum import FG, ProcessExecutionError, local # type: ignore pip = local[self.pip] - _ = pip["install", "--upgrade", "pip"] & FG pipeline = pip[ "install", @@ -330,6 +330,23 @@ def get_pip_from_venv(venv_path: Path) -> str: return str(venv_path.expanduser().resolve() / pip) +def upgrade_pip(venv_path: Path) -> str | None: + """ + Upgrade the pip executable in the given virtual environment + """ + + python = "Scripts\\python.exe" if OS == "Windows" else "bin/python" + python = str(venv_path.expanduser().resolve() / python) + + try: + result = subprocess.check_output([python, "-m", "pip", "install", "--upgrade", "pip"]).decode() + except subprocess.CalledProcessError as e: + print(e) + result = None + + return result + + def set_sys_path(venv_path: Path) -> None: """ Given a path to a virtual environment, set the sys.path, in a cross-platform fashion,