Home > front end >  When .py file become executable it stop running and stuck
When .py file become executable it stop running and stuck

Time:10-10

So I have this simple python script (main.py):

import sys
from webdriver_manager.chrome import ChromeDriverManager
import undetected_chromedriver as uc


def do_work():
    print(sys.argv)
    driver = uc.Chrome(executable_path=ChromeDriverManager().install())
    driver.get('http://www.cnn.com')


if __name__ == '__main__':
    do_work()

So this .py file works fine and I convert it to exe file using pyinstallser:

pyinstaller --onefile C:\Users\myuser\Desktop\proj\main.py

And when I try to run the exe file its look like it stuck at the print of my arguments and not started my browser.

This is the input:

C:\Users\raviv>C:\Users\raviv\dist\main.exe bla bla

And this is the output (all the last lines continue and it seems like dead lock...):

['C:\\Users\\myuser\\dist\\main.exe', 'bla', 'bla']
['C:\\Users\\myuser\\dist\\main.exe', '--multiprocessing-fork', 'parent_pid=15632', 'pipe_handle=732']
['C:\\Users\\myuser\\dist\\main.exe', '--multiprocessing-fork', 'parent_pid=16956', 'pipe_handle=736']
['C:\\Users\\myuser\\dist\\main.exe', '--multiprocessing-fork', 'parent_pid=7672', 'pipe_handle=736']
['C:\\Users\\myuser\\dist\\main.exe', '--multiprocessing-fork', 'parent_pid=17280', 'pipe_handle=728']
['C:\\Users\\myuser\\dist\\main.exe', '--multiprocessing-fork', 'parent_pid=12048', 'pipe_handle=716']
['C:\\Users\\myuser\\dist\\main.exe', '--multiprocessing-fork', 'parent_pid=18204', 'pipe_handle=728']

CodePudding user response:

You need to add freeze_support to the script because one of your imported modules is using multiprocessing under the hood.

Try this:

import sys
from webdriver_manager.chrome import ChromeDriverManager
import undetected_chromedriver as uc
from multiprocessing import freeze_support
freeze_support()


def do_work():
    print(sys.argv)
    driver = uc.Chrome(executable_path=ChromeDriverManager().install())
    driver.get('http://www.cnn.com')


if __name__ == '__main__':
    do_work()

It should work fine after that.

  • Related