Почему мой файл .exe не работает на других компьютерах? - PullRequest
0 голосов
/ 02 мая 2020

Я сделал исполняемый файл программы python, которую сделал. Он импортирует селен, хромедрайвер, запросы и модули OS. Когда я запускаю файл .exe после ввода необходимых входных данных в консоли, веб-сайт, на который указывает моя программа, не открывается. И консоль закрывается немедленно

from selenium import webdriver
from time import sleep
import requests
import os


class YoutubeBot():
    def __init__(self,url_list,path):
        self.driver = webdriver.Chrome(executable_path ="F:/Environments/project1_env/lib/site-packages/chromedriver/chromedriver.exe")
        self.url_list= url_list
        self.path = path


    def download(self):
        print("Starting Download.")
        sleep(2)
        c = 0
        for self.url in self.url_list:


            self.driver.get("https://en.savefrom.net/15/")

            sleep(6)
            self.driver.find_element_by_xpath('//*[@id="sf_url"]').send_keys(self.url)
            self.driver.find_element_by_xpath('//*[@id="sf_submit"]').click()
            sleep(15)
            #self.driver.find_element_by_xpath('//*[@id="sf_result"]/div/div[1]/div[2]/div[2]/div[2]').click()
            #elf.driver.find_element_by_xpath('//*[@id="sf_result"]/div/div[1]/div[2]/div[2]/div[2]/div[2]/div/div/div[1]/a[1]').click()
            self.driver.find_element_by_xpath('//*[@id="sf_result"]/div/div[1]/div[2]/div[2]/div[1]/a').click()
            #exit()
            if c<5:
                self.driver.switch_to.window(self.driver.window_handles[2])
                sleep(2)
                self.driver.close()
                sleep(2)
                self.driver.switch_to.window(self.driver.window_handles[0])
            c =c +1


    def startfile(self):
        print('Opening File')
        sleep(2)

        os.startfile('{}'.format(self.path))

url_list = input().split(" ")
path = input("Path of the folder where the files have to be downloaded. \n")
my_bot = YoutubeBot(url_list,path)
my_bot.download()
my_bot.startfile()

Я использовал cx_Freeze, чтобы преобразовать его в .exe файл. Код для этого ниже:

        from cx_Freeze import setup , Executable
    setup(name = 'YoutubeBot',
            version ='0.2',
            description = 'Bot',
            executables = [Executable("F:\projects\\YoutubeBot\\youtube_bot.py")])

ошибка:

Traceback (most recent call last):
  File "F:\Environments\project1_env\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
  File "c:\users\hp\appdata\local\programs\python\python38-32\lib\subprocess.py", line 854, in __init__
  File "c:\users\hp\appdata\local\programs\python\python38-32\lib\subprocess.py", line 1307, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "F:\Environments\project1_env\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 40, in run
  File "F:\Environments\project1_env\lib\site-packages\cx_Freeze\initscripts\Console.py", line 37, in run
  File "F:\projects\YoutubeBot\youtube_bot.py", line 48, in <module>
  File "F:\projects\YoutubeBot\youtube_bot.py", line 9, in __init__
  File "F:\Environments\project1_env\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
  File "F:\Environments\project1_env\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
...