How to enable chromedriver with pyinstaller?

I am using pyinstaller to create the executable of my python script.
In the script, I use these imports:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
etc...

The problem is that on startup pyinstaller myscript.pythis will turn on Firefox instead of Chrome. In the folder with the results c: ... \ dist \ myscript \ selenium \ webdriver there is a firefox folder, so it just skips the chromedriver, and for me this is a serious problem, because the script must run with Chrome.
There are only a few questions in this thread, but there is no answer to this question.
I was thinking about adding a tag --hidden-import MODULENAMEto the command, but chromedriver.exe is not a module ... Thanks

+4
source share
1 answer

It should be added as a binary file, since it is a binary file ...
Thus, a special specification file is required, in which the chrome transmission path in the local system and the desired location relative to dist \ myscript must be defined, so it looks something like this:

.....
a = Analysis(['myscript.py'],
             pathex=['path\\to\\my\\script'],
             binaries=[ ('path\\to\\my\\chromedriver.exe', '.\\selenium\\webdriver') ],
             datas=None,
....

And then run pyinstaller with this specification file: pyinstaller myscript.spec myscript.py

+4
source

Source: https://habr.com/ru/post/1655009/


All Articles