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

Windows10 Bash环境下Chromedriver在PATH中但Selenium报错求助

Fixing ChromeDriver Issues with Python 2.7 in Windows 10 Bash Shell

Hey there, let's work through this ChromeDriver problem you're hitting in the Windows Bash Shell (I’m assuming this is WSL, right?). The key thing to remember here is that the Bash environment doesn’t share Windows' PATH directly, and there are a few other gotchas with Python 2.7 and cross-environment tooling. Here's what to try:

  • Don’t rely on Windows' PATH for WSL Bash
    When you added ChromeDriver to Windows' PATH, that only affects Windows apps—your Bash shell has its own separate environment variables. To fix this:

    1. First, find the WSL equivalent path of your ChromeDriver. If it’s in C:\tools\chromedriver.exe, in Bash that becomes /mnt/c/tools/chromedriver.exe.
    2. Either update your Python code to use this WSL-style path explicitly:
      from selenium import webdriver
      driver = webdriver.Chrome(executable_path='/mnt/c/tools/chromedriver.exe')
      
    3. Or add the path to your Bash PATH variable permanently:
      • Open ~/.bashrc in a text editor (like nano ~/.bashrc)
      • Add this line at the end: export PATH="$PATH:/mnt/c/tools" (replace with your actual folder path)
      • Save and run source ~/.bashrc to apply the changes immediately.
  • Verify ChromeDriver-Chrome Version Compatibility
    This is one of the most common causes of errors. ChromeDriver must match the major version of your installed Chrome browser. For example, if you’re running Chrome 118.x, you need ChromeDriver 118.x—using an older or newer version will throw errors. Double-check this first!

  • Check Your Selenium Version for Python 2.7
    Python 2.7 is end-of-life, so the latest Selenium versions don’t support it. Make sure you’re using a compatible Selenium release—Selenium 3.x is the last major version that works with Python 2.7. You can install it with:

    pip install selenium==3.141.0
    
  • Test ChromeDriver Directly in Bash
    Before blaming your Python code, test if ChromeDriver runs at all in the Bash shell. Run the full path to the executable:

    /mnt/c/tools/chromedriver.exe --version
    

    If this throws an error, you might have a WSL compatibility issue. For WSL2, you may need to ensure Windows Subsystem for Linux is updated, or try running Chrome in headless mode in your Python code (since WSL doesn’t have a GUI by default):

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    chrome_options = Options()
    chrome_options.add_argument("--headless")
    chrome_options.add_argument("--no-sandbox")
    driver = webdriver.Chrome(executable_path='/mnt/c/tools/chromedriver.exe', options=chrome_options)
    

Give these steps a try—most likely the PATH mismatch between Windows and WSL is the main culprit, but checking version compatibility never hurts!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 09:19:48