[英]Chromedriver Path Error when converting to .exe Pyinstaller
I am having an issue with Pyinstaller including the chromedriver when converting to .exe. 转换为.exe时,Pyinstaller包括chromedriver出现问题。 The code works perfectly in python, does not work in the application. 该代码在python中完美运行,在应用程序中不起作用。
I keep receiving this error: 我不断收到此错误:
(base) C:\Users\NDEERING\Desktop\Audit Assistant>"C:\Users\NDEERING\Desktop\Audi
t Assistant\dist\Audit Auto Beta.exe"
Traceback (most recent call last):
File "site-packages\selenium\webdriver\common\service.py", line 76, in start
File "subprocess.py", line 775, in __init__
File "subprocess.py", line 1178, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Beta.py", line 46, in <module>
browser = webdriver.Chrome(chromedriver_path)
File "site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __ini
t__
File "site-packages\selenium\webdriver\common\service.py", line 83, in start
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executabl
e needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chrome
driver/home
I have already formatted my code to switch to sys._MEIPASS. 我已经格式化了代码以切换到sys._MEIPASS。
if getattr(sys, 'frozen', False):
# executed as a bundled exe, the driver is in the extracted folder
chromedriver_path = os.path.join(sys._MEIPASS, "chromedriver.exe")
browser = webdriver.Chrome(chromedriver_path)
IEdriver_path = os.path.join(sys._MEIPASS, "IEDriverServer")
browser = webdriver.Chrome(IEdriver_path)
chromedriver = "C:\\Users\\NDEERING\\Desktop\\Python\\chromedriver.exe"
browser = webdriver.Chrome(executable_path=chromedriver)
IeDriver = "C:\\Users\\NDEERING\\Desktop\\Python\\IEDriverServer.exe"
browseri = webdriver.Ie(executable_path=IeDriver)
and my .spec includes both of the drivers I am attempting to use: 而我的.spec包括我尝试使用的两个驱动程序:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['Beta.py'],
pathex=['C:\\Users\\NDEERING\\Desktop\\Audit Assistant'],
binaries=[('C:\\Users\\NDEERING\\Desktop\\Audit Assistant\\chromedriver.exe','Drivers'),('C:\\Users\\NDEERING\\Desktop\\Audit Assistant\\IEDriverServer.exe','Drivers')],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='Audit Auto Beta',
debug=False,
strip=False,
upx=True,
runtime_tmpdir=None,
console=True )
I would like for the program to run properly on both my PC and other PC's. 我希望该程序可以在我的PC和其他PC上正常运行。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!
You can use pyi-archive-viewer to inspect the .exe file contents, my expectation is that you're adding binaries under Drivers
folder and your Python script is looking for them in the current folder. 您可以使用pyi-archive-viewer检查.exe文件的内容,我的期望是要在Drivers
文件夹下添加二进制文件,而Python脚本正在当前文件夹中寻找它们。
So something like: 所以像这样:
chromedriver_path = os.path.join(sys._MEIPASS, "Drivers/chromedriver.exe")
should do the trick for you. 应该为您解决问题。
More information: 更多信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.