python - 扩展名为 .ipynb/.py 的 Python 程序在转换为 .exe 时不起作用?
问题描述
我正在尝试创建一个程序的可执行文件,该程序会打开一个链接并每半小时进行一次登录并继续计算时间。它是用 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()
我收到以下错误(对不起,图像质量,这是我能做到的最好的):
解决方案
好的。因此,由于没有人回答我的问题,我认为如果我自己澄清一下就好了,因为我已经弄清楚了。
我设法通过进行 2 项更改使其工作 - 1. 使用 win10toast 进行通知而不是 plyer 2. 确保在从命令提示符创建 .exe 时导入图像。为此,我在命令提示符下使用了这个命令:
pyinstaller -F --onefile -i "C:\user\.....(location of the image)" filename.py
这优雅地解决了我的问题。
推荐阅读
- kotlin - org.springframework.data.mapping.MappingException 与 Kotlin 和密封类
- json - 尽管请求 JSON,Dynamic 365 API 仅返回 XML
- java - Windows 上的 Java 编译器不会创建可执行文件,只有 .class
- javascript - 如何在一定量的反应后使反应消失?
- node.js - 如何在我的 Flutter 应用程序中获取服务器发送事件?
- mysql - MySQL:优化格式化日期的左连接
- python - 在 python selenium 中通过 span 文本查找按钮
- ruby-on-rails - Sidekiq 在特定队列中查找与特定实例相关的作业
- javascript - Couchbase 到 PouchDB 不同步现有文档
- javascript - 使用 Ramda 存储临时值的模式