{"record":{"id":"0918125d30d9fb61","repo":"assafelovic/gpt-researcher","slug":"unable-to-import-pkg-kebab-please-install-with","errorCode":null,"errorMessage":"Unable to import {pkg_kebab}. Please install with `pip install -U {pkg_kebab}`","messagePattern":"Unable to import (.+?)\\. Please install with `pip install -U (.+?)`","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"gpt_researcher/retrievers/utils.py","lineNumber":56,"sourceCode":"                    \"step\": step,\n                    \"content\": content\n                })\n        except Exception as e:\n            logger.error(f\"Error streaming output: {e}\")\n\ndef check_pkg(pkg: str) -> None:\n    \"\"\"\n    Checks if a package is installed and raises an error if not.\n    \n    Args:\n        pkg (str): The package name\n    \n    Raises:\n        ImportError: If the package is not installed\n    \"\"\"\n    if not importlib.util.find_spec(pkg):\n        pkg_kebab = pkg.replace(\"_\", \"-\")\n        raise ImportError(\n            f\"Unable to import {pkg_kebab}. Please install with \"\n            f\"`pip install -U {pkg_kebab}`\"\n        )\n\n# Valid retrievers for fallback\nVALID_RETRIEVERS = [\n    \"tavily\",\n    \"groundroute\",\n    \"custom\",\n    \"duckduckgo\",\n    \"searchapi\",\n    \"serper\",\n    \"serpapi\",\n    \"google\",\n    \"searx\",\n    \"bing\",\n    \"brave\",\n    \"arxiv\",","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/retrievers/utils.py#L38-L74","documentation":"check_pkg() uses importlib.util.find_spec to verify a retriever's optional dependency is importable before the retriever is instantiated. If find_spec returns None, it raises ImportError with a pip install hint naming the kebab-cased package. This is GPT Researcher's guard for its pluggable retriever backends.","triggerScenarios":"Selecting a retriever whose optional dependency isn't installed (e.g., 'tavily' without tavily-python, 'serpapi' without google-search-results, or any retriever package not in your env); __init__ calls check_pkg(pkg) and the ImportError fires immediately at construction time.","commonSituations":"Installing gpt-researcher without the optional extra for the chosen retriever; running in a different virtualenv/conda env than the one where the package was installed; renamed or yanked PyPI packages; mixing pip and system Python so find_spec can't see the installed package.","solutions":["Install the named package exactly as the message suggests: pip install -U <pkg-kebab> (e.g., pip install -U tavily-python).","Install the relevant optional extra, e.g., pip install -U gpt-researcher[tavily], to pull all needed deps at once.","Confirm you're in the same virtualenv/interpreter you think you are (which python; which pip) and reinstall there.","Switch to a retriever with no extra dependencies (e.g., 'duckduckgo') if you can't install packages."],"exampleFix":"# before\n# retrieval provider 'tavily' selected, tavily-python not installed\nretriever = TavilySearch(query)  # ImportError: Unable to import tavily-python. ...\n\n# after\n# pip install -U tavily-python\nretriever = TavilySearch(query)  # works","handlingStrategy":"validation","validationCode":"import importlib.util\n\npkg = 'tavily-python'  # or the retriever's dependency\nif importlib.util.find_spec(pkg.replace('-', '_')) is None:\n    raise SystemExit(f'{pkg} is required: pip install -U {pkg}')","typeGuard":"def has_pkg(module_name: str) -> bool:\n    return importlib.util.find_spec(module_name) is not None","tryCatchPattern":"try:\n    retriever = make_retriever(provider)\nexcept ImportError as e:\n    print(f'Missing optional dependency: {e}')\n    retriever = make_retriever('duckduckgo')  # dependency-free fallback","preventionTips":["Install optional extras for every retriever you plan to use (pip install gpt-researcher[extra]).","Pin optional dependencies in requirements.txt to avoid surprise missing modules.","Run a startup dependency audit that check_pkg-style validates each enabled provider.","Default to a dependency-free retriever like duckduckgo in minimal installs."],"tags":["import-error","optional-dependency","pip","retriever","configuration"],"backgroundTag":"missing-optional-dependency","analyzedSha":"6f998577d547b1e54ec662dac63583aa11e3b84b","analyzedAt":"2026-08-28T17:50:07.383Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}