crewAIInc/crewAI · error · ImportError

Failed to install 'patronus' package

Error message

Failed to install 'patronus' package

What it means

Raised by PatronusLocalEvaluatorTool when the user consented to the interactive install prompt but the underlying `uv add patronus` subprocess failed (non-zero exit). The tool attempts a just-in-time dependency install via subprocess with check=True; CalledProcessError is caught and re-raised as this ImportError, chained from the original failure.

Source

Thrown at lib/crewai-tools/src/crewai_tools/tools/patronus_eval_tool/patronus_local_evaluator_tool.py:76

            if PYPATRONUS_AVAILABLE:
                self.client = patronus_client
                self._generate_description()
            else:
                raise ImportError
        except ImportError:
            import click

            if click.confirm(
                "You are missing the 'patronus' package. Would you like to install it?"
            ):
                import subprocess

                try:
                    subprocess.run(["uv", "add", "patronus"], check=True)  # noqa: S607
                    self.client = patronus_client
                    self._generate_description()
                except subprocess.CalledProcessError as e:
                    raise ImportError("Failed to install 'patronus' package") from e
            else:
                raise ImportError(
                    "`patronus` package not found, please run `uv add patronus`"
                ) from None

    def _run(
        self,
        **kwargs: Any,
    ) -> Any:
        evaluated_model_input = kwargs.get("evaluated_model_input")
        evaluated_model_output = kwargs.get("evaluated_model_output")
        evaluated_model_retrieved_context = kwargs.get(
            "evaluated_model_retrieved_context"
        )
        evaluated_model_gold_answer = self.evaluated_model_gold_answer
        evaluator = self.evaluator

        result: Any = self.client.evaluate(

View on GitHub (pinned to 754d7323be)

Solutions

  1. Install patronus manually: uv add patronus (or pip install patronus) from the project root, then rerun
  2. If uv is missing, install it (curl -LsSf https://astral.sh/uv/install.sh | sh) or pre-install the package with pip so the prompt never appears
  3. Run the process from the uv project root with a writable pyproject.toml/uv.lock
  4. Check the chained CalledProcessError (__cause__) for the real uv failure (network, resolver, permissions)
  5. Pre-install dependencies in Docker/CI images so the interactive prompt path is never hit

Example fix

# before
python run_agent.py  # prompt accepted, uv missing -> ImportError

# after (pre-install in Dockerfile / CI)
RUN uv add patronus
# or: RUN pip install patronus
Defensive patterns

Strategy: try-catch

Validate before calling

import importlib.util, shutil

def patronus_installable() -> bool:
    return importlib.util.find_spec("patronus") is not None or shutil.which("uv") is not None

Try / catch

try:
    tool = PatronusLocalEvaluatorTool(...)
except ImportError as e:
    if "install" in str(e).lower():
        subprocess.run(["pip", "install", "patronus"], check=True)
        tool = PatronusLocalEvaluatorTool(...)
    else:
        raise

Prevention

When it happens

Trigger: The patronus package is not importable, click.confirm returns True, and `uv add patronus` exits non-zero — e.g. uv is not on PATH in the current venv/container, the project is not a uv-managed workspace, pyproject.toml is read-only, network offline, or dependency resolution fails.

Common situations: Running inside Docker or CI where uv is not installed or PATH differs; running from a directory without a uv project; lockfile conflicts; restricted file permissions on pyproject.toml; no network access to PyPI.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/3de265d17ecdc142. Report an issue: GitHub.