扩展名为.ipynb / .py的Python程序在转换为.exe后不起作用?

问题描述 投票:0回答:1

我正在尝试创建程序的可执行文件,该文件会打开一个链接并每半小时进行一次登录,并继续计时。它已在Jupyter Notebook中编写。该代码在Jupyter(.ipynb)/。py中工作正常,但转换为.exe时会抛出错误,提示"Fatal error Detected -Failed to execute script"。代码如下:

from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from plyer import notification

i=1
while i<=20:
    notification.notify(
    title="Initiating Session Number {}".format(i),
    message='Marking Attendance',
    app_icon=r"C:\Users\91800\Downloads\Documents\automation\aut.ico", 
    timeout=6,  # seconds
    )
    options = webdriver.ChromeOptions()
    options.add_argument('--ignore-ssl-errors=yes')
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--allow-running-insecure-content')
    driver = webdriver.Chrome(options=options)

    driver.get('https://120.72.92.102:10443/remote/login?lang=en')
    WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "username")))

    username = driver.find_element_by_id("username")
    password = driver.find_element_by_id("credential")

    username.send_keys("pranjal.pathak")
    password.send_keys("zxc^567")

    driver.find_element_by_id("login_button").click()
    time.sleep(10)
    driver.close()

我收到以下错误(很抱歉,图像质量,这是我能尽力解决的最好问题:]

enter image description here

python python-3.x jupyter-notebook
1个回答
0
投票

好。因此,由于没有人回答我的问题,所以我自己弄清楚就可以了,因为我已经弄清楚了。

我设法进行了2处更改,使其能够正常工作,1.用win10toast代替pyer进行通知2.确保在命令提示符下制作.exe时导入图像。为此,我在命令提示符下使用了此命令:

pyinstaller -F --onefile -i "C:\user\.....(location of the image)" filename.py

这很好地解决了我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.