Skip to content

pyinstaller does not put browser in exe file build #45

Open
@harbet333

Description

@harbet333

i have a code:

import asyncio
import json
import os
from patchright.async_api import async_playwright

SESSION_FILE = "session.json"
URL = "https://www.twitch.tv/login"  

class BrowserSession:
    async def load_session(self, browser):
        """Load session."""
        if os.path.exists(SESSION_FILE):
            with open(SESSION_FILE, "r") as f:
                storage_state = json.load(f)
            return await browser.new_context(storage_state=storage_state)
        return await browser.new_context()

    async def save_session(self, context):
        """save session."""
        storage = await context.storage_state()
        with open(SESSION_FILE, "w") as f:
            json.dump(storage, f)
        print("sesion saved")

    async def run(self):
        async with async_playwright() as p:
            browser = await p.chromium.launch(headless=False)
            context = await self.load_session(browser)
            page = await context.new_page()
            
            await page.goto(URL)
            print(f"Open page: {URL}")
            print("Press Enter to save session and exit...")
            
            # waiting Enter
            loop = asyncio.get_event_loop()
            await loop.run_in_executor(None, input)
            
            await self.save_session(context)
            await browser.close()

if __name__ == "__main__":
    session = BrowserSession()
    asyncio.run(session.run())

this code works in visual studio code in venv

I try to create an exe file to execute it, but no matter what I enter in the terminal, it does not include the browser in the exe file, and therefore nothing works

I tried:

set PLAYWRIGHT_BROWSERS_PATH=0
playwright install chromium
pyinstaller -F main.py
set PLAYWRIGHT_BROWSERS_PATH=0
patchright install chromium
pyinstaller -F main.py
set PATCHRIGHT_BROWSERS_PATH=0
patchright install chromium
pyinstaller -F main.py
set PATCHRIGHT_BROWSERS_PATH=0
playwright install chromium
pyinstaller -F main.py

None of these methods work. Please , help me , when using the standard playwright in the code, the command from the manual works https://playwright.dev/python/docs/library

set PLAYWRIGHT_BROWSERS_PATH=0
playwright install chromium
pyinstaller -F main.py

but the standard playwright does not allow logging into twitch

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomershelp wantedExtra attention is neededwontfixThis will not be worked on

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions