遇到的情况:
使用pyinstaller -w -F打包selenium
在大部分机器上运行正常 但是少数机器上运行报错
selenium版本:3.141.0
报错内容:
Message: ‘chromedriver.exe’ executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
关键代码:
chrome_location = './Chrome/chrome.exe'
chrome_path = "./Chrome/chromedriver.exe"
browser = webdriver.Chrome(chrome_path,options=options)
在网上查了许多方法,比如将chromedriver和exe一起打包等等都不管用
后来发现是打包时加了-w参数的话 导致python安装路径下的\selenium\webdriver\common\service.py
里面的subprocess.Popen
失效
解决办法:
subprocess.Popen修改为:
self.process = subprocess.Popen(cmd, env=self.env,
close_fds=platform.system() != 'Windows',
# stdout=self.log_file,
# stderr=self.log_file,
stdin=PIPE,
creationflags=134217728,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
再将调用selenium的代码改为文章来源:https://www.toymoban.com/news/detail-575022.html
from os import getcwd
chrome_location = getcwd() + '/Chrome/chrome.exe'
chrome_path = getcwd() + "/Chrome/chromedriver.exe"
browser = webdriver.Chrome(chrome_path,options=options)
即可解决文章来源地址https://www.toymoban.com/news/detail-575022.html
到了这里,关于pyinstaller打包selenium报错找不到webdriver的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!