在按照答案(How to include chromedriver with pyinstaller?)中的建議更新Pyinstaller spec文件後,仍然沒有從生成的應用程序文件訪問chromedriver。這個問題可以與.\\selenium\\webdriver
?這是從答案複製,我不確定它是特定於Windows操作系統。Pyinstaller生成的應用程序沒有鏈接到指定的二進制文件(chromedriver)
在終端中運行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
在終端用於產生該應用。
是,「\\ \\硒webdriver的」表示一個Windows相對路徑。這是將chromedriver二進制文件放入捆綁包的位置。在Unix上,它將是./selenium/webdriver。但是,我在Windows上嘗試過這種方法,但它仍然將chromedriver放在那裏。在生成的捆綁包中是否有可執行chromedriver的dist/selenium/webdriver dirs? – monami
謝謝,這有幫助。但是,如果將chromedriver放置在/ usr/bin(而不是/ usr/local/bin)中,目前該應用程序可以工作,顯然不管放置在spec文件中。你知道,如果chromedriver可以捆綁在產生的應用程序/ exe文件? – Phillip
但是在運行pyinstaller之後,chromedriver可執行文件是否存在於「bundlepath」/ dist/selenium目錄中?你如何在你的python代碼中設置chromedriver?當它捆綁時,你不使用PATH,但設置路徑爲chromedriver像這樣(這是一個遠程示例):'dir = os.path.dirname(__ file__) chrome_path = os.path.join(dir,' selenium','webdriver','chromedriver.exe') service = service.Service(chrome_path)...' – monami