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

时间:2020-03-24 02:24:20

标签: python python-3.x jupyter-notebook

我正在尝试创建程序的可执行文件,该程序会打开一个链接并每半小时进行一次登录,并继续计时。它已用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

1 个答案:

答案 0 :(得分:0)

好的。因此,由于没有人回答我的问题,我认为自己已经弄清楚了,如果我自己加以澄清,那是很好的。

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

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

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

相关问题