{"record":{"id":"7da26e56fd233c0e","repo":"crewAIInc/crewAI","slug":"tavily-python-has-been-installed-please-restart-7da26e","errorCode":null,"errorMessage":"'tavily-python' has been installed. Please restart your Python application to use the TavilySearchTool.","messagePattern":"'tavily-python' has been installed\\. Please restart your Python application to use the TavilySearchTool\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/tavily_search_tool/tavily_search_tool.py","lineNumber":140,"sourceCode":"                api_key=self.api_key, proxies=self.proxies, client_name=\"crewai\"\n            )\n        else:\n            try:\n                import subprocess\n\n                import click\n            except ImportError as e:\n                raise ImportError(\n                    \"The 'tavily-python' package is required. 'click' and 'subprocess' are also needed to assist with installation if the package is missing. \"\n                    \"Please install 'tavily-python' manually (e.g., 'pip install tavily-python') and ensure 'click' and 'subprocess' are available.\"\n                ) from e\n\n            if click.confirm(\n                \"You are missing the 'tavily-python' package, which is required for TavilySearchTool. Would you like to install it?\"\n            ):\n                try:\n                    subprocess.run([\"uv\", \"add\", \"tavily-python\"], check=True)  # noqa: S607\n                    raise ImportError(\n                        \"'tavily-python' has been installed. Please restart your Python application to use the TavilySearchTool.\"\n                    )\n                except subprocess.CalledProcessError as e:\n                    raise ImportError(\n                        f\"Attempted to install 'tavily-python' but failed: {e}. \"\n                        f\"Please install it manually to use the TavilySearchTool.\"\n                    ) from e\n            else:\n                raise ImportError(\n                    \"The 'tavily-python' package is required to use the TavilySearchTool. \"\n                    \"Please install it with: uv add tavily-python\"\n                )\n\n    def _run(\n        self,\n        query: str,\n    ) -> str:\n        \"\"\"Synchronously performs a search using the Tavily API.","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/tavily_search_tool/tavily_search_tool.py#L122-L158","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install the dependency before starting your process: uv add tavily-python (or pip install tavily-python), then restart the Python application/notebook kernel.","Add 'crewai-tools[tools]' or explicitly list tavily-python in your project dependencies so the install prompt never appears.","In notebooks, restart the kernel after installation; in servers, restart the service.","Pre-install in Dockerfiles/CI: RUN uv add tavily-python as a build step."],"exampleFix":"# before (running in an already-started process)\ntool = TavilySearchTool(api_key='tvly-...')  # prompts, installs, then raises ImportError\n\n# after (install first, then start the app)\n# terminal: uv add tavily-python\n# then restart your app / kernel\ntool = TavilySearchTool(api_key='tvly-...')","handlingStrategy":"validation","validationCode":"import importlib.util, sys\n\nif importlib.util.find_spec('tavily') is None:\n    sys.exit(\"tavily-python missing - run 'uv add tavily-python' and restart\")","typeGuard":null,"tryCatchPattern":"try:\n    tool = TavilySearchTool(api_key=KEY)\nexcept ImportError as e:\n    if 'restart' in str(e):\n        # package just installed mid-process; restart required\n        os.execv(sys.executable, [sys.executable, *sys.argv])\n    raise","preventionTips":["Declare tavily-python as an explicit project dependency instead of relying on the interactive installer.","Run dependency smoke checks (importlib.util.find_spec) at app startup before constructing tools.","Never rely on installing packages into a running interpreter; always restart."],"tags":["dependencies","import","installation","restart-required"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}