Linux Mint下Selenium调用Chromedriver报状态码127错误求助
解决Selenium ChromeDriver状态码127退出问题
看起来你碰到的这个127错误在Linux Mint下挺常见的,大多是ChromeDriver缺少运行依赖、权限不足或者环境配置的问题,我给你几个靠谱的排查和解决步骤:
检查ChromeDriver的执行权限
先打开终端,执行以下命令查看文件权限:ls -l /usr/bin/chromedriver看看输出里的权限列(比如
-rwxr-xr-x)有没有x(执行权限),如果没有,用这条命令添加权限:sudo chmod +x /usr/bin/chromedriver排查缺失的系统依赖库
直接在终端手动运行ChromeDriver,它会给出具体的缺失依赖提示:/usr/bin/chromedriver比如常见的缺失库有
libglib2.0-0、libnss3、libgconf-2-4等,根据提示用apt安装对应的库,举个通用的安装命令覆盖大部分常见缺失:sudo apt install libgconf-2-4 libnss3 libxss1 libappindicator1 libindicator7确认Chrome浏览器与Driver版本匹配且正常安装
虽然你说版本正确,但还是再确认下Chrome是否安装以及版本:google-chrome --version如果没安装Chrome,直接用这条命令安装稳定版:
sudo apt install google-chrome-stable优化代码初始化方式并修复URL错误
你的代码里URL写的http:google.com是格式错误的,应该是https://google.com;另外Selenium 3及以上版本更推荐用Service类来初始化Driver,试试修改代码:from selenium import webdriver from selenium.webdriver.chrome.service import Service service = Service("/usr/bin/chromedriver") driver = webdriver.Chrome(service=service) driver.get("https://google.com")检查PyCharm的Python环境配置
确保PyCharm使用的Python解释器和你安装Selenium的环境一致:- 打开PyCharm的
Settings(File -> Settings) - 进入
Project: 你的项目名->Python Interpreter - 确认列表里有
selenium,如果用了虚拟环境,要确保已经在虚拟环境内安装了Selenium
- 打开PyCharm的
内容的提问来源于stack exchange,提问作者kjtn99
相关产品推荐
相关产品推荐

