問題描述
我正在使用 pyinstaller 創(chuàng)建我的 python 腳本的可執(zhí)行文件.
在腳本中我使用了這些導(dǎo)入:
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...
問題是,當(dāng)運行 pyinstaller myscript.py
時,會導(dǎo)致包含 Firefox,而不是 Chrome.結(jié)果文件夾 c:...distmyscriptseleniumwebdriver 有一個 firefox 文件夾,所以它只是跳過了 chromedriver,這對我來說是一個嚴(yán)重的問題,因為腳本需要與 Chrome 一起運行.
圍繞這個主題只有幾個問題,但沒有解決問題的答案.
我正在考慮將 --hidden-import MODULENAME
標(biāo)簽添加到命令中,但 chromedriver.exe 不是模塊...謝謝
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
推薦答案
應(yīng)該添加為二進制文件,因為是二進制文件...
因此,需要一個自定義規(guī)范文件,其中應(yīng)該定義本地系統(tǒng)上 chromedriver 的路徑以及相對于 distmyscript 的所需位置,因此它看起來像這樣:
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,
....
然后使用這個規(guī)范文件運行 pyinstaller:pyinstaller myscript.spec myscript.py
And then run the pyinstaller with this spec file: pyinstaller myscript.spec myscript.py
這篇關(guān)于如何在 pyinstaller 中包含 chromedriver?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!