From dc2f18934d7567143ebc6a2310870442d143afc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Perceval=20Wajsb=C3=BCrt?= Date: Tue, 15 Apr 2025 16:57:36 +0200 Subject: [PATCH] fix: try several paths to find current pip executable --- changelog.md | 1 + edsnlp/core/pipeline.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 9bbc57634..2a479a534 100644 --- a/changelog.md +++ b/changelog.md @@ -10,6 +10,7 @@ - `edsnlp.package` now correctly detect if a project uses an old-style poetry pyproject or a PEP621 pyproject.toml. - PEP621 projects containing nested directories (e.g., "my_project/pipes/foo.py") are now supported. +- Try several paths to find current pip executable ## v0.16.0 (2025-0.3-26) diff --git a/edsnlp/core/pipeline.py b/edsnlp/core/pipeline.py index 1c71e91fb..e324264a1 100644 --- a/edsnlp/core/pipeline.py +++ b/edsnlp/core/pipeline.py @@ -1305,10 +1305,22 @@ def load_from_huggingface( new_mtime = max(os.path.getmtime(x) for x in Path(path).rglob("*")) should_install = new_mtime != mtime - pip = os.path.join(sysconfig.get_path("scripts"), "pip") + pip_paths = [ + os.path.join(sys.exec_prefix, "bin", "pip"), + os.path.join(sys.executable.rsplit("/", 1)[0], "pip"), + os.path.join(sysconfig.get_path("scripts"), "pip"), + os.path.join(sys.exec_prefix, "bin", "pip3"), + os.path.join(sys.executable.rsplit("/", 1)[0], "pip3"), + os.path.join(sysconfig.get_path("scripts"), "pip3"), + ] + pip = next((p for p in pip_paths if os.path.exists(p)), None) + pip = pip or shutil.which("pip") + if should_install or not any( p.startswith(module_name) and p.endswith(".dist-info") for p in os.listdir(path) ): + if pip is None: + raise RuntimeError(f"Couldn't find pip amongst {', '.join(pip_paths)}") subprocess.run( [pip, "install", "-e", path, "--target", path, "--no-deps", "--upgrade"] ) @@ -1344,6 +1356,8 @@ def load_from_huggingface( f"pip install {' '.join((repr(str(dep)) for dep in missing_deps))}", UserWarning, ) + if pip is None: + raise RuntimeError(f"Couldn't find pip amongst {', '.join(pip_paths)}") subprocess.run([pip, "install", *(str(d) for d in missing_deps)]) module = importlib.import_module(module_name) return module.load(**kwargs)