简体   繁体   English

转换为.exe Pyinstaller时的Chromedriver路径错误

[英]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.

相关问题 将.py转换为.exe时出现Pyinstaller错误 - Pyinstaller Error when converting .py to .exe Python pyinstaller 将 py 转换为 exe 时出错 - Python pyinstaller error when converting py to exe 转换为exe时出现Python pyinstaller错误 - Python pyinstaller error when converting to exe 使用 pyinstaller 转换为 exe 时出现 Moviepy 模块错误 - Moviepy module error when converting to exe with pyinstaller Pyinstaller 在运行 .exe 时给出“'chromedriver.exe' 可执行文件需要在 PATH 中”,但实际的 python 脚本工作正常 - Pyinstaller gives “ 'chromedriver.exe' executable needs to be in PATH” when the .exe is ran, but the actual python script works fine 使用 pyinstaller 将 python 文件转换为 an.exe 文件时出现 opencv 错误 - opencv error when converting a python file to an .exe file with pyinstaller Pyinstaller - “致命错误! 将脚本转换为 exe 时无法执行脚本” - Pyinstaller - “Fatal error ! Failed to execute script” when converting script to exe Pyinstaller --windowed或--noconsole .exe不允许chromedriver打开 - Pyinstaller --windowed or --noconsole .exe not allowing chromedriver to open Pyinstaller 运行 exe 文件时出错 - Pyinstaller Error when running the exe file 尝试创建 exe 文件时出现 Pyinstaller 错误 - Pyinstaller Error when try to create exe file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM