Reputation: 23
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)
Upvotes: 0
Views: 812
Reputation: 63
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()
Upvotes: 1