I have developed a selenium automation using python to get some data. When I run counter.py file it works fine and able to get what I wanted. Proceed with packing my file using pyinstaller and again tested it works fine on same machine.
The issue here is when I take this exe and run on other computer it wouldn't run and instantly closes the cmd, was able to capture error with debug True as below stating chromedriver.exe not found.
I try creating exact same directory on second machine similar to what is stated in executable_path= and worked fine after placing my chromedriver.exe. My question is there any way I can pack these without needing chromedriver.exe at all on other machine.
counter.py
....
options = Options()
options.add_argument("--headless")
browser = webdriver.Chrome(executable_path=r"C:\Users\jasme\Desktop\project1\chromedriver.exe", options=options)
url = "https://en.wikipedia.org/wiki/Wiki"
browser.get(url)
....
counter.spec
a = Analysis(['counter.py'],
pathex=['C:\\Users\\jasme\\Desktop\\project1'],
binaries=[('C:\\Users\\jasme\\Desktop\\project1\\chromedriver.exe','\\selenium\\webdriver')],
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='counter',
debug=True,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True )
Error
[20396] LOADER: callfunction returned...
[20396] LOADER: extracted pyimod03_importers
[20396] LOADER: callfunction returned...
[20396] LOADER: Installing PYZ archive with Python modules.
[20396] LOADER: PYZ archive: PYZ-00.pyz
[20396] LOADER: Running pyibootOl_bootstrap.py
[20396] LOADER: Running counter.py
Traceback (most recent call last):
File "site-packages\selenium\webdriver\common\service.py", line 76, in start
File "subprocess.py", line 800, in _init_
File "subprocess.py", line 1207, 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 "counter.py", line 35, in <module>
File "site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in _init_
File "site-packages\selenium\webdriver\common\service.py", line 83, in start
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH.
Please see https://sites.google.com/a/chromium.org/chromedriver/home
[20396] Failed to execute script counter
[20396] LOADER: OK.
[20396] LOADER: Cleaning up Python interpreter.
[2264] LOADER: Back to parent (RC: -1) 2
P.S: sorry if the title is confusing maybe someone can modify it.