Chromedriver 路径 转换为 Pyinstaller 时出错.exe



我在转换为 .exe 时遇到了 Pyinstaller 问题,包括 chromedriver。代码在python中完美运行,在应用程序中不起作用。

我不断收到此错误:

(base) C:UsersNDEERINGDesktopAudit Assistant>"C:UsersNDEERINGDesktopAudi
t AssistantdistAudit Auto Beta.exe"
Traceback (most recent call last):
File "site-packagesseleniumwebdrivercommonservice.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-packagesseleniumwebdriverchromewebdriver.py", line 73, in __ini
t__
File "site-packagesseleniumwebdrivercommonservice.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

我已经格式化了我的代码以切换到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)

我的 .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 )

我希望该程序在我的 PC 和其他 PC 上正常运行。 任何帮助将不胜感激。谢谢!

您可以使用pyi-archive-viewer来检查.exe文件内容,我的期望是您在Drivers文件夹下添加二进制文件,并且您的Python脚本正在当前文件夹中查找它们。

所以像这样:

chromedriver_path = os.path.join(sys._MEIPASS, "Drivers/chromedriver.exe")

应该为你做这个伎俩。

更多信息:

  • PyInstaller:高级主题
  • 如何在pyinstaller之后使用捆绑程序--add-binary
  • 硒与蟒蛇

相关内容

  • 没有找到相关文章

最新更新