{"record":{"id":"4919b3e8a3dfae42","repo":"huggingface/smolagents","slug":"you-must-install-wikipedia-api-to-run-this-tool","errorCode":null,"errorMessage":"You must install `wikipedia-api` to run this tool: for instance run `pip install wikipedia-api`","messagePattern":"You must install `wikipedia-api` to run this tool: for instance run `pip install wikipedia-api`","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"src/smolagents/default_tools.py","lineNumber":598,"sourceCode":"        \"query\": {\n            \"type\": \"string\",\n            \"description\": \"The topic to search on Wikipedia.\",\n        }\n    }\n    output_type = \"string\"\n\n    def __init__(\n        self,\n        user_agent: str = \"Smolagents (myemail@example.com)\",\n        language: str = \"en\",\n        content_type: str = \"text\",\n        extract_format: str = \"WIKI\",\n    ):\n        super().__init__()\n        try:\n            import wikipediaapi\n        except ImportError as e:\n            raise ImportError(\n                \"You must install `wikipedia-api` to run this tool: for instance run `pip install wikipedia-api`\"\n            ) from e\n        if not user_agent:\n            raise ValueError(\"User-agent is required. Provide a meaningful identifier for your project.\")\n\n        self.user_agent = user_agent\n        self.language = language\n        self.content_type = content_type\n\n        # Map string format to wikipediaapi.ExtractFormat\n        extract_format_map = {\n            \"WIKI\": wikipediaapi.ExtractFormat.WIKI,\n            \"HTML\": wikipediaapi.ExtractFormat.HTML,\n        }\n\n        if extract_format not in extract_format_map:\n            raise ValueError(\"Invalid extract_format. Choose between 'WIKI' or 'HTML'.\")\n","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/default_tools.py#L580-L616","documentation":"Raised by WikipediaSearchTool.__init__ when the optional `wikipedia-api` package is not installed. smolagents keeps it optional, and the tool fails at construction with an ImportError chained from the ModuleNotFoundError.","triggerScenarios":"Instantiating WikipediaSearchTool without `pip install wikipedia-api`. Any constructor call (default or custom args) hits the import check first.","commonSituations":"Fresh installs without extras, notebooks where smolagents was installed long before the tool was first used, CI environments with minimal dependency sets.","solutions":["pip install wikipedia-api.","Add it to requirements/pyproject so environments are reproducible.","Confirm the package name: it is `wikipedia-api` on PyPI (imports as `wikipediaapi`), not `wikipedia`."],"exampleFix":"# before\ntool = WikipediaSearchTool()  # ImportError\n# after\n# pip install wikipedia-api\ntool = WikipediaSearchTool()","handlingStrategy":"validation","validationCode":"try:\n    import wikipediaapi  # noqa\nexcept ImportError:\n    raise SystemExit('pip install wikipedia-api')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Note PyPI name is wikipedia-api, import name is wikipediaapi.","Add optional deps to pinned requirements when enabling the tool."],"tags":["dependency","import-error","wikipedia","smolagents"],"backgroundTag":"missing-optional-dependency","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}