按照此处的答案 (How to include chromedriver with pyinstaller?) 中的建议更新 Pyinstaller 规范文件后,仍然无法从生成的应用程序文件访问 chromedriver。问题可能出在 .\\selenium\\webdriver
上吗?这是从答案中复制的,我不确定它是否特定于 Windows 操作系统。
在终端运行 UNIX 可执行文件,访问 chromedriver。
完整的规范文件是:
# -*- mode: python -*-
block_cipher = None
a = Analysis([‘scriptname.py'],
pathex=['/Users/Name/Desktop'],
binaries=[('/usr/local/bin/chromedriver', '.\\selenium\\webdriver')],
datas=None,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name=‘app name’,
debug=False,
strip=False,
upx=True,
console=False )
app = BUNDLE(exe,
name=‘appname.app',
icon=None,
bundle_identifier=None)
在终端中使用 pyinstaller appname.spec scriptname.py --windowed --onefile
行来生成应用程序。
最佳答案
是的,那是 Windows 路径。在 Unix 中,您需要使用 ./selenium/webdriver
代替。它告诉将 chromedriver 二进制文件放在包中的什么位置,因此在 pyinstall 之后,chromedriver 将位于 /path/to/bundle/dist/selenium/webdriver
.
然后在代码中你应该使用这样的东西来达到它(这是一个远程示例):
dir = os.path.dirname(__file__)
chrome_path = os.path.join(dir, 'selenium','webdriver','chromedriver.exe')
service = service.Service(chrome_path) ...
关于python - Pyinstaller 生成的应用程序未链接到指定的二进制文件 (chromedriver),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41009492/