Pyinstaller 生成的应用程序不会 link 到指定的二进制文件 (chromedriver)

Pyinstaller generated app does not link to the specified binary (chromedriver)

按照此处答案 () 中的建议更新 Pyinstaller 规范文件后,仍然无法从生成的应用程序文件访问 chromedriver。问题可能出在 .\selenium\webdriver 上吗?这是从答案中复制的,我不确定它是否特定于 Windows OS。

运行 终端中的 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) ...