Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
506 views
in Technique[技术] by (71.8m points)

python - How to include chromedriver with pyinstaller?

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:...distmyscriptseleniumwebdriver 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 distmyscript 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...