Pyinstaller生成的应用程序未链接到指定的二进制文件(chromedriver)

发布于 2021-02-01 11:32:22

按照此处的答案(如何在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用于终端以生成应用程序。

关注者
0
被浏览
67
1 个回答
  • 面试哥
    面试哥 2021-02-01
    为面试而生,有面试问题,就找面试哥。

    是的,那是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) ...
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看