0

I'm try to compile python to exe with Pyinstaller and it's successful but exe programm not working.Nothing happens. Using modules: selenium and multiprocessing. When i run the script via python idle everything works as it should.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from multiprocessing import Pool
import time

def start(url):
    options = webdriver.ChromeOptions()
    options.add_argument('headless')
    options.add_argument('window-size=1920x935')
    browser = webdriver.Chrome("chromedriver.exe", chrome_options = options)
    wait = WebDriverWait(browser, 10)
    browser.get(url)
    browser.switch_to.window(browser.window_handles[-1])
    wait.until(EC.visibility_of_element_located((By.XPATH, '//* 
    [@id="movie_player"]/div[33]/div[2]/div[1]/button'))).click()
    wait.until(EC.visibility_of_element_located((By.XPATH, '//* 
    [@id="movie_player"]/div[33]/div[2]/div[1]/span/button'))).click()
    time.sleep(180)
    browser.quit()

if __name__ == '__main__':
    links = open('links.txt', encoding = 'utf-8', errors='ignore')
    urls = []
    for i in links:
        urls.append(i)
    try:
        p = Pool(processes = len(urls))
        p.map(start, urls)
    except Exception as e:
        print(e)
2
  • 2
    Try running your executable through a commandline to see if you get an exception. Commented Sep 26, 2022 at 17:29
  • Since it's Selenium, even though your code is error-free, you may face different runtime errors that don't get caught during compilation, you may run it once on an editor and print all the statuses to see where is the error engendering from. Commented Sep 26, 2022 at 17:31

1 Answer 1

1

I am assuming windows platform and there is known issue with pyinstaller and multiprocessing , wrap your current main function in main() and call the changes as shown below, Give this a try.

if __name__ == '__main__':
    # On Windows, Multiprocessing code fails when using a --onefile executable.
    # This problem is specific to Windows, we need the freeze_support to handle this case
    # Reference: https://github.com/pyinstaller/pyinstaller/issues/182
    freeze_support()
    main()

Not the answer you're looking for? Browse other questions tagged or ask your own question.