Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

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

After updating the Pyinstaller spec file as suggested in the answer here (How to include chromedriver with pyinstaller?), chromedriver is still not being accessed from the generated app file. Could the issue be with .\selenium\webdriver? That was copied from the answer and I'm not sure it's specific to a Windows OS.

Running the UNIX executable in terminal works, accessing chromedriver.

The full spec file is:

# -*- 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)

The line pyinstaller appname.spec scriptname.py --windowed --onefile is used in terminal to generate the app.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, that was Windows path. In Unix, use ./selenium/webdriver instead. It tells where to place the chromedriver binary in the bundle, so after pyinstall, chromedriver will be in /path/to/bundle/dist/selenium/webdriver.
Then in the code you should use something like this to reach it (it's a remote example):

dir = os.path.dirname(__file__)
chrome_path = os.path.join(dir, selenium','webdriver','chromedriver.exe')
service = service.Service(chrome_path) ... 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...