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

Categories

0 votes
1.5k 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 Reply

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) ... 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...