13

I am using pyinstaller to create an executable of my python script.
In the script I'm using these imports:

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

The problem is, when running pyinstaller myscript.py , it will result in including Firefox, instead of Chrome. In the result folder c:...\dist\myscript\selenium\webdriver there is a firefox folder, so it is simply skipping chromedriver, and it is a serious problem for me, because the script needs to run with Chrome.
There is only a few questions around this topic, but there is no answer to solve the issue.
I was thinking on adding the --hidden-import MODULENAME tag to the command, but chromedriver.exe is not a module... Thanks

monami
  • 594
  • 2
  • 9
  • 32
  • 2
    You could add is as a [data file](https://pythonhosted.org/PyInstaller/spec-files.html#adding-files-to-the-bundle), but I am not sure that it will solve the issue. – Repiklis Sep 19 '16 at 11:03
  • 1
    Thanks, I'll try this out. In the meantime, I found a workaround, that is, installing chromedriver on the target machine, and adding its folder to the Path, but I must find something without it. – monami Sep 19 '16 at 13:57
  • Why not adding your idea as an answer? :) It solved my problem, I added chromedriver.exe as a binary file to the spec. Thanks again! – monami Sep 20 '16 at 20:27
  • @Repiklis sorry I forgot to mention you... – monami Sep 21 '16 at 18:28
  • 2
    I am glad it worked. You found the solution. I just gave you a hint. – Repiklis Sep 22 '16 at 08:40

1 Answers1

12

It should be added as a binary file, since it is a binary file...
So a custom spec file needed where the chromedriver's path on the local system and the desired location relative to the dist\myscript should 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 the pyinstaller with this spec file: pyinstaller myscript.spec myscript.py

monami
  • 594
  • 2
  • 9
  • 32
  • I have a [question](http://stackoverflow.com/questions/41009492/pyinstaller-generated-app-does-not-link-to-the-specified-binary-chromedriver) regarding your answer – ballade4op52 Dec 07 '16 at 04:40
  • Here is an updated [question](http://stackoverflow.com/questions/41030257/is-there-a-way-to-bundle-a-binary-file-such-as-chromedriver-with-a-single-file) – ballade4op52 Dec 08 '16 at 01:25
  • Here is pyinstaller example explained in details. https://hackernoon.com/the-one-stop-guide-to-easy-cross-platform-python-freezing-part-1-c53e66556a0a. And here how packaging works https://python-packaging.readthedocs.io/en/latest/everything.html – Hrvoje T Jan 30 '19 at 00:10
  • How about firefox webdriver? – Heinz Jul 17 '19 at 17:20