crewAIInc/crewAI · error · ImportError

'tavily-python' has been installed. Please restart your Pyth

Error message

'tavily-python' has been installed. Please restart your Python application to use the TavilySearchTool.

What it means

TavilySearchTool imports the optional 'tavily-python' package lazily. When the import fails, it interactively offers to install the package via 'uv add tavily-python'. If that subprocess succeeds, the tool still cannot use the freshly installed package because Python's import system has already cached the failure, so it raises ImportError telling you to restart the application so a new interpreter process picks up the new package.

Source

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

                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:
                raise ImportError(
                    "The 'tavily-python' package is required to use the TavilySearchTool. "
                    "Please install it with: uv add tavily-python"
                )

    def _run(
        self,
        query: str,
    ) -> str:
        """Synchronously performs a search using the Tavily API.

View on GitHub (pinned to 754d7323be)

Solutions

  1. Install the dependency before starting your process: uv add tavily-python (or pip install tavily-python), then restart the Python application/notebook kernel.
  2. Add 'crewai-tools[tools]' or explicitly list tavily-python in your project dependencies so the install prompt never appears.
  3. In notebooks, restart the kernel after installation; in servers, restart the service.
  4. Pre-install in Dockerfiles/CI: RUN uv add tavily-python as a build step.

Example fix

# before (running in an already-started process)
tool = TavilySearchTool(api_key='tvly-...')  # prompts, installs, then raises ImportError

# after (install first, then start the app)
# terminal: uv add tavily-python
# then restart your app / kernel
tool = TavilySearchTool(api_key='tvly-...')
Defensive patterns

Strategy: validation

Validate before calling

import importlib.util, sys

if importlib.util.find_spec('tavily') is None:
    sys.exit("tavily-python missing - run 'uv add tavily-python' and restart")

Try / catch

try:
    tool = TavilySearchTool(api_key=KEY)
except ImportError as e:
    if 'restart' in str(e):
        # package just installed mid-process; restart required
        os.execv(sys.executable, [sys.executable, *sys.argv])
    raise

Prevention

When it happens

Trigger: Instantiating TavilySearchTool(api_key=...) in an environment where 'tavily-python' is not installed, then answering 'y' to the click.confirm prompt; the subprocess.run(['uv','add','tavily-python'], check=True) succeeds and this ImportError is raised immediately after.

Common situations: Running a CrewAI crew in a long-lived process (Jupyter notebook, Streamlit app, agent server) that was started before tavily-python was installed; using uv-managed projects where 'uv add' succeeds but the current interpreter is not the project venv; CI jobs that answer prompts automatically.

Related errors


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