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

标签 python selenium selenium-chromedriver pyinstaller

按照此处的答案 (How to include chromedriver with pyinstaller?) 中的建议更新 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 行来生成应用程序。

最佳答案

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

关于python - Pyinstaller 生成的应用程序未链接到指定的二进制文件 (chromedriver),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41009492/

相关文章:

python - 在 python 解释器中输入一个对象的名称 - 它调用什么方法?

python - Tensorflow获取原始框架而不是边界框绘制框架

java - 错误:The method elementToBeClickable(By) in the type ExpectedConditions is not applicable for the arguments (WebElement)

java - 返回页面引用作为页面上操作的结果?

python - Google chrome 与 selenium 一起启动后立即关闭

Python Selenium ConnectionResetError : [WinError 10054] An existing connection was forcibly closed by the remote host

python - 复杂地将嵌套字典转换为python中的对象

python - Python 的 XPath 语法

java - 如何使用 selenium webdriver 在 div 标签中找到 P 标签

java - org.openqa.selenium.json.JsonOutput.write(Ljava/lang/Object;Ljava/lang/reflect/Type;) 由于 JsonException : Attempting to close incomplete json stream