From 01692787ed7f7c3b9b3ae9ae26980f5447b05b99 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Thu, 22 Jul 2021 15:02:44 +0530 Subject: [PATCH 1/2] docs(pyinstaller): added docs for pyinstaller --- 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 b6c482d417dbc..5e3fec3d9005a 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 +pyinstaller -F main.py + +# Windows with PowerShell +$env:PLAYWRIGHT_BROWSERS_PATH="0" +playwright install +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 From 1566ae685ff7deee537afb59d47ab5f2d9f235d2 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Thu, 22 Jul 2021 13:12:53 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- docs/src/intro-python.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/intro-python.md b/docs/src/intro-python.md index 5e3fec3d9005a..9d3eece9e6100 100644 --- a/docs/src/intro-python.md +++ b/docs/src/intro-python.md @@ -161,12 +161,12 @@ pyinstaller -F main.py # Windows with cmd.exe set PLAYWRIGHT_BROWSERS_PATH=0 -playwright install +playwright install chromium pyinstaller -F main.py # Windows with PowerShell $env:PLAYWRIGHT_BROWSERS_PATH="0" -playwright install +playwright install chromium pyinstaller -F main.py ```