按照此处的答案(如何在pyinstaller中包含chromedriver?)更新了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) ...
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句