How to include chromedriver with pyinstaller?(如何在 pyinstaller 中包含 chromedriver?)
问题描述
我正在使用 pyinstaller 创建我的 python 脚本的可执行文件.
在脚本中我使用了这些导入:
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...
问题是,当运行 pyinstaller myscript.py
时,会导致包含 Firefox,而不是 Chrome.结果文件夹 c:...distmyscriptseleniumwebdriver 有一个 firefox 文件夹,所以它只是跳过了 chromedriver,这对我来说是一个严重的问题,因为脚本需要与 Chrome 一起运行.
围绕这个主题只有几个问题,但没有解决问题的答案.
我正在考虑将 --hidden-import MODULENAME
标签添加到命令中,但 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
推荐答案
应该添加为二进制文件,因为是二进制文件...
因此,需要一个自定义规范文件,其中应该定义本地系统上 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,
....
然后使用这个规范文件运行 pyinstaller:pyinstaller myscript.spec myscript.py
And then run the pyinstaller with this spec file: pyinstaller myscript.spec myscript.py
这篇关于如何在 pyinstaller 中包含 chromedriver?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 pyinstaller 中包含 chromedriver?


- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01