crewAIInc/crewAI · error · ImportError

The 'tavily-python' package is required. 'click' and 'subpro

Error message

The 'tavily-python' package is required. 'click' and 'subprocess' are also needed to assist with installation if the package is missing. Please install 'tavily-python' manually (e.g., 'pip install tavily-python') and ensure 'click' and 'subprocess' are available.

What it means

TavilySearchTool raises this ImportError in __init__ when tavily-python is missing and the installer helper modules (click, subprocess) also fail to import. The interactive install prompt never runs because the helper imports abort first; the message suggests pip install tavily-python.

Source

Thrown at lib/crewai-tools/src/crewai_tools/tools/tavily_search_tool/tavily_search_tool.py:130

        ]
    )

    def __init__(self, **kwargs: Any):
        super().__init__(**kwargs)
        if TAVILY_AVAILABLE:
            self.client = TavilyClient(
                api_key=self.api_key, proxies=self.proxies, client_name="crewai"
            )
            self.async_client = AsyncTavilyClient(
                api_key=self.api_key, proxies=self.proxies, client_name="crewai"
            )
        else:
            try:
                import subprocess

                import click
            except ImportError as e:
                raise ImportError(
                    "The 'tavily-python' package is required. 'click' and 'subprocess' are also needed to assist with installation if the package is missing. "
                    "Please install 'tavily-python' manually (e.g., 'pip install tavily-python') and ensure 'click' and 'subprocess' are available."
                ) from e

            if click.confirm(
                "You are missing the 'tavily-python' package, which is required for TavilySearchTool. Would you like to install it?"
            ):
                try:
                    subprocess.run(["uv", "add", "tavily-python"], check=True)  # noqa: S607
                    raise ImportError(
                        "'tavily-python' has been installed. Please restart your Python application to use the TavilySearchTool."
                    )
                except subprocess.CalledProcessError as e:
                    raise ImportError(
                        f"Attempted to install 'tavily-python' but failed: {e}. "
                        f"Please install it manually to use the TavilySearchTool."
                    ) from e
            else:

View on GitHub (pinned to 754d7323be)

Solutions

  1. pip install tavily-python click (or uv add tavily-python) before creating the tool.
  2. Pin tavily-python in project dependencies so the import always succeeds.
  3. Avoid the fallback path in sandboxes by pre-installing everything.

Example fix

# before
tool = TavilySearchTool()  # -> ImportError

# after
# shell: pip install tavily-python
tool = TavilySearchTool()
Defensive patterns

Strategy: try-catch

Validate before calling

import importlib.util
if importlib.util.find_spec("tavily") is None or importlib.util.find_spec("click") is None:
    raise SystemExit("Install first: pip install tavily-python click")

Try / catch

try:
    tool = TavilySearchTool(api_key=os.environ["TAVILY_API_KEY"])
except ImportError as e:
    raise SystemExit(f"Missing dependency: {e}. Run: pip install tavily-python") from e

Prevention

When it happens

Trigger: Constructing TavilySearchTool in an environment where TAVILY_AVAILABLE is False and click (or subprocess) cannot be imported.

Common situations: Slim Docker images lacking click; locked-down runners; crewai-tools installed without optional extras.

Related errors


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