{"record":{"id":"decd2adda5f02f71","repo":"assafelovic/gpt-researcher","slug":"selenium-is-required-but-not-installed-see-error","errorCode":null,"errorMessage":"Selenium is required but not installed. See error message above for installation instructions.","messagePattern":"Selenium is required but not installed\\. See error message above for installation instructions\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"gpt_researcher/scraper/browser/browser.py","lineNumber":95,"sourceCode":"        try:\n            global webdriver, By, EC, WebDriverWait, TimeoutException, WebDriverException\n            from selenium import webdriver\n            from selenium.webdriver.common.by import By\n            from selenium.webdriver.support import expected_conditions as EC\n            from selenium.webdriver.support.wait import WebDriverWait\n            from selenium.common.exceptions import TimeoutException, WebDriverException\n\n            global ChromeOptions, FirefoxOptions, SafariOptions\n            from selenium.webdriver.chrome.options import Options as ChromeOptions\n            from selenium.webdriver.firefox.options import Options as FirefoxOptions\n            from selenium.webdriver.safari.options import Options as SafariOptions\n        except ImportError as e:\n            print(f\"Failed to import Selenium: {str(e)}\")\n            print(\"Please install Selenium and its dependencies to use BrowserScraper.\")\n            print(\"You can install Selenium using pip:\")\n            print(\"    pip install selenium\")\n            print(\"If you're using a virtual environment, make sure it's activated.\")\n            raise ImportError(\n                \"Selenium is required but not installed. See error message above for installation instructions.\") from e\n\n    def setup_driver(self) -> None:\n        # print(f\"Setting up {self.selenium_web_browser} driver...\")\n\n        options_available = {\n            \"chrome\": ChromeOptions,\n            \"firefox\": FirefoxOptions,\n            \"safari\": SafariOptions,\n        }\n\n        options = options_available[self.selenium_web_browser]()\n        options.add_argument(f\"user-agent={self.user_agent}\")\n        if self.headless:\n            options.add_argument(\"--headless\")\n        options.add_argument(\"--enable-javascript\")\n\n        try:","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/scraper/browser/browser.py#L77-L113","documentation":"BrowserScraper lazily imports Selenium in _import_selenium() during __init__. If the selenium package (or a transitive import like its browser driver bits) cannot be imported, the scraper prints installation instructions to stdout and re-raises an ImportError chained from the original exception. The scraper cannot start without Selenium installed.","triggerScenarios":"Creating a BrowserScraper when 'import selenium' fails — selenium not installed, installed in another environment, or a broken/partial install where a submodule import raises ImportError. __init__ calls _import_selenium(), which catches ImportError, prints help, and raises this error 'from e'.","commonSituations":"Using the browser scraper feature without pip install selenium; running under a different interpreter than expected; selenium partially upgraded leaving broken modules; missing webdriver-manager or a driver binary — though the driver itself usually fails later in setup_driver, broken imports surface here.","solutions":["Install Selenium in the active environment: pip install selenium (plus pip install webdriver-manager if the project uses it).","Confirm the right interpreter: which python / pip -V, and reinstall if pip installed to a different env.","If the original import error names a missing submodule, reinstall cleanly: pip uninstall selenium && pip install selenium.","As an alternative, use a scraper backend without Selenium (e.g., the plain http/requests scraper or NoDriverScraper with zendriver)."],"exampleFix":"# before\nscraper = BrowserScraper(url)  # ImportError: Selenium is required but not installed...\n\n# after\n# pip install selenium webdriver-manager\nscraper = BrowserScraper(url)","handlingStrategy":"validation","validationCode":"import importlib.util\n\nif importlib.util.find_spec('selenium') is None:\n    raise SystemExit('selenium is required for BrowserScraper: pip install selenium')","typeGuard":"def selenium_available() -> bool:\n    try:\n        importlib.util.find_spec('selenium')\n        import selenium  # catches broken installs too\n        return True\n    except (ImportError, ModuleNotFoundError):\n        return False","tryCatchPattern":"try:\n    scraper = BrowserScraper(url)\nexcept ImportError as e:\n    if 'Selenium is required' in str(e):\n        scraper = HttpScraper(url)  # non-browser fallback\n    else:\n        raise","preventionTips":["Install selenium (and webdriver-manager) in every env that uses the browser scraper.","Feature-detect selenium at startup and fall back to a plain HTTP scraper.","Pin selenium versions in requirements to avoid broken upgrades.","In containers, also install/verify the browser binary (chromium) and driver."],"tags":["selenium","import-error","browser-scraper","scraping","dependency"],"backgroundTag":"missing-optional-dependency","analyzedSha":"6f998577d547b1e54ec662dac63583aa11e3b84b","analyzedAt":"2026-08-28T17:50:07.383Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}