[Python] How can I continue to use the chrome.exe correctly in the exe file packaged with...

Discussão em 'Python' iniciado por Stack, Setembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    I wrote a web script using a playwright(a python library) for auto-login, and now I want to use this script on other computers (without installing any dependencies). What should I do in order to package chrome.exe?

    I've tried to use


    pyinstaller --onefile --noconsole --add-data "C:\Users\29267\AppData\Local\ms-playwright\chromium-1134\chrome-win\chrome.exe;." .\auto_login.py
    ​

    but the exe formed doesn't run properly (New to programming, code is a bit bad, please forgive me~ THX)

    import os
    import sys
    from playwright import sync_api


    class funcDocker(object):
    def __init__(self, account, password):
    self.account = account
    self.password = password

    def get_chromium_path(self):
    # Check if you are running in the packaged environment(AI wrote it)
    if getattr(sys, "frozen", False):
    chromium_path = os.path.join(sys._MEIPASS,".")
    else:
    # Use local path
    chromium_path = r"C:\Users\29267\AppData\Local\ms-playwright\chromium-1134\chrome-win\chrome.exe"
    return chromium_path

    def run_playwright(self):
    with sync_api.sync_playwright() as p:
    chromium_path = self.get_chromium_path()

    browser = p.chromium.launch(headless=True, executable_path=chromium_path)

    # code_for_auto_login



    if __name__ == "__main__":
    func_docker = funcDocker("my_account", "my_password")
    func_docker.run_playwright()



    I had written a program that depended on a whole folder, and then I used "pyinstaller ... --add-data "the_path/bin; bin" ... " .After packaging, it worked fine

    def get_poppler_path(self):
    if getattr(sys, "frozen", False):
    poppler_path = os.path.join(sys._MEIPASS, "bin")
    else:
    poppler_path = "D:/the_path/bin"
    return poppler_path


    So I don't really understand what the problem is, you know.

    What I expect is func "get_chromium_path" and instructions on the command line, Thank you so much!

    Continue reading...

Compartilhe esta Página