FileNotFoundError
FileNotFoundError: [Errno 2] No such file or directory: 'chromium'
Stack trace
FileNotFoundError: [Errno 2] No such file or directory: 'chromium' at pyppeteer.chromium_downloader.download_chromium (chromium_downloader.py:123) at pyppeteer.launcher.launch (launcher.py:45) at main.py:15
Why it happens
Browser automation libraries like pyppeteer or Playwright require a Chromium browser executable to launch. This error occurs when Chromium is not installed, not downloaded, or the executable path is incorrect or missing in the environment.
Detection
Check for FileNotFoundError exceptions when launching the browser and verify if the Chromium executable path exists on the filesystem before runtime.
Causes & fixes
Chromium browser is not installed or downloaded on the system.
Run the library's install or download command (e.g., 'playwright install' or pyppeteer's chromium download) to install Chromium.
The executable path for Chromium is not set or is incorrect in the launch configuration.
Explicitly specify the correct path to the Chromium executable in the browser launch options.
Environment PATH does not include the directory containing the Chromium executable.
Add the Chromium executable directory to the system PATH environment variable or provide the full path in code.
Code: broken vs fixed
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch() # FileNotFoundError: chromium not found here
page = browser.new_page()
page.goto('https://example.com')
print(page.title())
browser.close() import os
from playwright.sync_api import sync_playwright
os.environ['PLAYWRIGHT_BROWSERS_PATH'] = '0' # Use bundled browsers or set custom path
with sync_playwright() as p:
browser = p.chromium.launch() # Fixed: chromium installed and path resolved
page = browser.new_page()
page.goto('https://example.com')
print(page.title())
browser.close() Workaround
Catch FileNotFoundError when launching the browser, then prompt the user to run the install command or manually specify the executable path to continue.
Prevention
Automate Chromium installation as part of your deployment or CI pipeline and always verify the executable path before launching the browser to avoid runtime errors.