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

Ubuntu系统下Python调用Selenium启动Firefox报错SessionNotCreatedException

解决Selenium启动Firefox时报错"Failed to start browser /snap/firefox/current/firefox.launcher"

问题原因

Ubuntu通过snap包安装的Firefox,其实际可执行文件路径与Selenium默认查找的/snap/firefox/current/firefox.launcher不匹配,导致找不到启动文件。

解决方案

1. 指定正确的Firefox二进制文件路径

先在终端执行命令确认Firefox实际路径:
which firefox
通常会返回/snap/bin/firefox,在代码中指定该路径即可:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.binary_location = '/snap/bin/firefox'
brow = webdriver.Firefox(options=options)

2. 配置geckodriver路径(若未在系统全局路径)

如果geckodriver没有放在/usr/local/bin这类系统可执行路径下,可在代码中直接指定其位置:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service

options = Options()
options.binary_location = '/snap/bin/firefox'
service = Service(executable_path='/your/path/to/geckodriver')
brow = webdriver.Firefox(service=service, options=options)

3. 确认版本兼容性

再次核对Firefox与geckodriver版本是否匹配:

  • 查看Firefox版本:firefox --version
  • 查看geckodriver版本:geckodriver --version
    比如Firefox 115+需搭配geckodriver 0.33及以上版本。

4. 重置Firefox snap包

若路径问题仍存在,尝试重新安装Firefox:

sudo snap remove firefox
sudo snap install firefox

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 01:16:09