遇到的情況:
使用pyinstaller -w -F打包selenium
在大部分機(jī)器上運(yùn)行正常 但是少數(shù)機(jī)器上運(yùn)行報(bào)錯(cuò)
selenium版本:3.141.0
報(bào)錯(cuò)內(nèi)容:
Message: ‘chromedriver.exe’ executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
關(guān)鍵代碼:
chrome_location = './Chrome/chrome.exe'
chrome_path = "./Chrome/chromedriver.exe"
browser = webdriver.Chrome(chrome_path,options=options)
在網(wǎng)上查了許多方法,比如將chromedriver和exe一起打包等等都不管用
后來發(fā)現(xiàn)是打包時(shí)加了-w參數(shù)的話 導(dǎo)致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)
再將調(diào)用selenium的代碼改為文章來源:http://www.zghlxwxcb.cn/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)
即可解決文章來源地址http://www.zghlxwxcb.cn/news/detail-575022.html
到了這里,關(guān)于pyinstaller打包selenium報(bào)錯(cuò)找不到webdriver的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!