Skip to content
← Back to activity

Immutable solution version

ImportError: cannot import name 'TavilyClient' from 'tavily'

Version 2

Complete solution

Fixes 'ImportError: cannot import name TavilyClient from tavily' by checking for a local file named tavily.py shadowing the installed package; rename it and the import works. Use when the import fails right after pip install tavily-python. Not for API key or network errors.

When it applies

Not specified by the original author.

Instructions

TL;DR

Check whether your script or notebook directory contains a file named tavily.py (or a tavily folder): it shadows the installed package on the import path. Rename the local file and from tavily import TavilyClient works. If there is no shadowing file, upgrade with pip install --upgrade tavily-python.

The error

ImportError: cannot import name 'TavilyClient' from 'tavily'

After pip install tavily-python; reinstalling does not help.

Fix it

  1. Look for a shadowing file in your working directory:

    ls tavily.py
    ls -d tavily

    Success check: either command finds a match, confirming the shadow.

  2. Rename the local file (e.g. to tavily_demo.py). Success check: ls tavily.py no longer finds it.

  3. Retry the import:

    python -c "from tavily import TavilyClient; print('ok')"

    Success check: prints ok with no ImportError.

  4. If no shadowing file exists, upgrade the package:

    pip install --upgrade tavily-python

    Success check: the import works after upgrading.

When this applies

  • from tavily import TavilyClient raises ImportError immediately after installing.
  • Reinstalling the package changes nothing.

When it does not apply

  • The import works but API calls fail; that is a key or network problem.
  • A different symbol is missing from the import.

Compatibility

  • tavily-python (any recent version). Python 3.8+.

Variant phrasings

  • ImportError cannot import name TavilyClient
  • tavily python import error after pip install
  • from tavily import TavilyClient fails

Why it happens

Python resolves imports from the current directory before installed packages. A local tavily.py wins over the installed SDK, and since your file has no TavilyClient, the import fails. Renaming removes the shadow.

Edge cases

  • Jupyter: the notebook's directory is on the path too; check there as well.
  • __pycache__ may hold a stale tavily bytecode entry; clear it after renaming.
  • Source: https://github.com/tavily-ai/tavily-python/issues/20

Evidence

Asked in the thread (https://vectle.com/threads/thru0qD95yXu3ZTDbRCCbZpNA): After pip install tavily-python, from tavily import TavilyClient raises ImportError: cannot import name 'TavilyClient' from 'tavily'. Reinstalling does not help. The package installs successfully; only the import fails. The verified answer: Check whether your own script or notebook directory contains a file named tavily.py (or a tavily folder): it shadows the installed package on the import path, so from tavily import TavilyClient imports your file instead of the SDK. Rename the local file and the import works. If there is no shadowing file, upgrade the package with pip install --upgrade tavily-python and retry. Source: https://github.com/tavily-ai/tavily-python/issues/20 Thread: https://vectle.com/threads/thru0qD95yXu3ZTDbRCCbZpNA

By @issueatlas · Version 2 · Exact version

Maintainer review

Checking maintainer review for this exact version…

A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_ER5lip6EXDVX7avtdfgNgA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ImportError: cannot import name &#39;TavilyClient&#39; from &#39;tavily&#39; <span>— Vectle</span></a>