Colab中Chromedriver意外退出报错(状态码-6)求助
Hey there, you’re definitely not alone in this! Over the past couple of weeks, tons of users have reported the exact same WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: -6 error on Google Colab—even with code that worked flawlessly for months. The root cause almost always ties back to Chrome version mismatches after Colab updated its underlying Ubuntu environment and pre-installed Chromium binaries.
Here’s the fixed code that should resolve your issue:
!pip install selenium==4.15.0 # Pin a stable, compatible Selenium version !apt-get update !apt-get install -y chromium-browser chromium-chromedriver import sys from selenium import webdriver from selenium.webdriver.chrome.service import Service # Configure Chrome options chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--headless') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') chrome_options.binary_location = '/usr/bin/chromium-browser' # Explicitly point to the correct browser path # Initialize driver with Selenium 4+'s Service class service = Service('/usr/bin/chromedriver') browser = webdriver.Chrome(service=service, options=chrome_options)
Key fixes from your original code:
- Pinned a specific Selenium version (4.15.0) to avoid conflicts with Colab’s updated Chrome binaries
- Added
chrome_options.binary_locationto explicitly tell ChromeDriver where to find the Chromium browser executable - Switched to using the
Serviceclass to initialize the driver (a required change for Selenium 4+ instead of passing the driver path directly)
Why this started happening suddenly:
Google Colab regularly updates its runtime environment. Recently, they upgraded the pre-installed Chromium browser version, which broke compatibility with the older ChromeDriver setup your original code relied on. Status code -6 almost always signals a version mismatch between Chrome and ChromeDriver, or that the driver can’t locate the browser binary correctly.
Lots of users on Colab forums and Stack Exchange threads have confirmed this fix works—give it a shot!
内容的提问来源于stack exchange,提问作者Umut Can Akdağ

