Python Playwright 打包报错 Please run the following command to download new browsers

715 阅读1分钟
  • 想做一个浏览器自动化的小插件,本地安装了 Playwright,测试可以正常打开浏览器自动化。

  • 但是在使用 PyInstallerPython 代码打包成 app/exe 后,打开应用程序报错:

    playwright._impl._api_types.Error: Executable doesn't exist at /Users/dengzemiao/Desktop/Project/python/dist/main/playwright/driver/package/.local-browsers/chromium-1033/chrome-mac/Chromium.app/Contents/MacOS/Chromium
    
    ╔════════════════════════════════════════════════════════════╗
    
    ║ Looks like Playwright was just installed or updated.       ║
    
    ║ Please run the following command to download new browsers: ║
    
    ║                                                            ║
    
    ║     playwright install                                     ║
    
    ║                                                            ║
    
    ║ <3 Playwright Team                                         ║
    
    ╚════════════════════════════════════════════════════════════╝
    
  • 原因是:Playwright 没有被打到包内,解决方案

    # 重新安装一下(chromium 是其中一个浏览器插件,看自己用什么就装什么)
    #  Expecting one of: chromium, chrome, chrome-beta, msedge, msedge-beta, msedge-dev, firefox, webkit
    $ PLAYWRIGHT_BROWSERS_PATH=0 playwright install chromium
    
    # 然后再次打包
    pyinstaller -F main.py