You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 20.04.3 LTS环境下Python项目启动Selenium ChromeDriver报错求助

Fixing Selenium WebDriver Issues on Ubuntu 20.04.3 LTS

Hey there, let's tackle those two issues you're facing with Selenium on Ubuntu 20.04.3 LTS—one's a quick fix for a deprecation warning, the other's the bigger problem of chromedriver exiting unexpectedly.

1. Squash the Deprecation Warning

That <stdin>:1: DeprecationWarning: use options instead of chrome_options message is straightforward: Selenium phased out the chrome_options parameter in favor of options for the Chrome driver constructor. You just need to update that line of code to use the new parameter name.

2. Fix the "Service chromedriver unexpectedly exited" Error

The status code 1 error almost always comes from a version mismatch between Chromium (or Chrome) and chromedriver, or unnecessary setup steps causing conflicts. Let's fix this step by step:

Step 1: Verify Version Compatibility

First, check your installed Chromium version to ensure it matches your chromedriver:

chromium-browser --version

If you installed via apt, the chromium-chromedriver package should already be paired with the correct Chromium version, but double-checking never hurts.

Step 2: Clean Up Your Setup Code

Your current code has redundant steps that might be causing path conflicts. Here's the simplified, working version:

# Update packages and install required tools
!apt-get update -y
!apt-get install -y chromium-browser chromium-chromedriver

# Import Selenium modules
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

# Configure Chrome options for headless mode
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')  # Extra flag for headless mode stability

# Initialize the driver (no need to specify chromedriver path—it's already in PATH)
wd = webdriver.Chrome(options=chrome_options)

Key Changes Explained:

  • Removed manual cp and sys.path steps: The chromium-chromedriver package installs chromedriver to a system PATH location automatically, so you don't need to copy it or add paths manually.
  • Swapped chrome_options=chrome_options for options=chrome_options to eliminate the deprecation warning.
  • Added --disable-gpu: While not strictly required for Linux headless mode, it can boost stability in some environments.

If the Error Still Happens:

If chromedriver still exits unexpectedly, download the exact chromedriver version matching your Chromium release, extract it, and overwrite the existing one in /usr/bin. Then restart your Python session to apply the change.


内容的提问来源于stack exchange,提问作者PDD

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 18:12:34