From 5701292a530aefc478b362a172e128f274e417b0 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Thu, 22 Jul 2021 19:17:29 +0530 Subject: [PATCH] docs(python): added docs for pyinstaller (#7784) Co-authored-by: Max Schmitt --- docs/src/intro-python.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/docs/src/intro-python.md b/docs/src/intro-python.md index b6c482d417..9d3eece9e6 100644 --- a/docs/src/intro-python.md +++ b/docs/src/intro-python.md @@ -4,6 +4,7 @@ title: "Getting Started" --- + - [Release notes](./release-notes.md) ## Installation @@ -135,6 +136,45 @@ python -m asyncio >>> await playwright.stop() ``` +## Pyinstaller + +You can use Playwright with [Pyinstaller](https://www.pyinstaller.org/) to create standalone executables. + +```py +# main.py +from playwright.sync_api import sync_playwright + +with sync_playwright() as p: + browser = p.chromium.launch() + page = browser.new_page() + page.goto("http://whatsmyuseragent.org/") + page.screenshot(path="example.png") + browser.close() +``` + +If you want to bundle browsers with the executables: + +```bash +# Linux/macOS +PLAYWRIGHT_BROWSERS_PATH=0 playwright install chromium +pyinstaller -F main.py + +# Windows with cmd.exe +set PLAYWRIGHT_BROWSERS_PATH=0 +playwright install chromium +pyinstaller -F main.py + +# Windows with PowerShell +$env:PLAYWRIGHT_BROWSERS_PATH="0" +playwright install chromium +pyinstaller -F main.py +``` + +:::note +Bundling the browsers with the executables will generate bigger binaries. +It is recommended to only bundle the browsers you use. +::: + ## Known issues ### `time.sleep()` leads to outdated state