简体   繁体   中英

Chromedriver Path Error when converting to .exe Pyinstaller

I am having an issue with Pyinstaller including the chromedriver when converting to .exe. The code works perfectly in python, does not work in the application.

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.

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:

# -*- 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. 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.

So something like:

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

should do the trick for you.

More information:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM