From 1eab48ef8e4484f2957a122b984b0291b113976b Mon Sep 17 00:00:00 2001 From: Vishal Punjabi <10079537+vshalpnjabi@users.noreply.github.com> Date: Thu, 29 Oct 2026 03:30:57 +0000 Subject: [PATCH] Pass --python sys.executable to the uv download fallback uv pip install without --python cannot find an unactivated uv venv and exits 2. Target the running interpreter, as the pip branch does. Fixes #14055 --- spacy/cli/download.py | 2 +- spacy/tests/test_cli.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/spacy/cli/download.py b/spacy/cli/download.py index 4690343af5..479bfd6b9d 100644 --- a/spacy/cli/download.py +++ b/spacy/cli/download.py @@ -193,7 +193,7 @@ def _get_pip_install_cmd() -> list: if importlib.util.find_spec("pip") is not None: return [sys.executable, "-m", "pip", "install"] elif shutil.which("uv"): - return ["uv", "pip", "install"] + return ["uv", "pip", "install", "--python", sys.executable] else: msg.fail( "No package installer found", diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index 4bac40f0b8..6cd3622b4b 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -1,5 +1,6 @@ import math import os +import sys from collections import Counter from pathlib import Path from typing import Any, Dict, List, Tuple @@ -1237,3 +1238,20 @@ def test_download_rejects_relative_urls(monkeypatch): download_module.download("en_core_web_sm-3.7.1", direct=True) with pytest.raises(SystemExit): download_module.download("../en_core_web_sm-3.7.1", direct=True) + + +@pytest.mark.issue(14055) +def test_get_pip_install_cmd_uv_uses_python_flag(monkeypatch): + """uv fallback must target the running interpreter in unactivated uv venvs.""" + monkeypatch.setattr( + download_module.importlib.util, + "find_spec", + lambda name: None if name == "pip" else True, + ) + monkeypatch.setattr( + download_module.shutil, + "which", + lambda name: "/usr/bin/uv" if name == "uv" else None, + ) + cmd = download_module._get_pip_install_cmd() + assert cmd == ["uv", "pip", "install", "--python", sys.executable]