我想用pyinstaller创建一个可执行程序,但是在成功创建文件之后,当我想运行该文件时,我有一个错误,这是我的代码:
# -*- coding: utf-8 -*-
"""
Created on Sun May 24 18:18:00 2020
@author: MeTaNa
"""
'''
this program is simple, notifys u if battery is fully charged,
'''
import psutil
from time import sleep
from win10toast import ToastNotifier
toaster = ToastNotifier()
while True:
battery = psutil.sensors_battery()
plugged = battery.power_plugged
percent = str(battery.percent)
if plugged==False: plugged="Not Plugged In"
else: plugged="Plugged In"
if (psutil.sensors_battery().power_plugged == True) and (battery.percent == 100):
print(percent+'% | '+plugged)
print('Unplug the Charger Please!')
toaster.show_toast('Battery Statues','Battery Full.\nUnplug the Charger Please!')
sleep(600)
elif (psutil.sensors_battery().power_plugged == False)and (battery.percent != 100):
print(percent+'% | '+plugged)
print('Thank Your.')
toaster.show_toast('Battery Statues','Charger Not Plugged')
sleep(3600)
else:
print(percent+'% | '+plugged)
print('Thank Your.')
toaster.show_toast('Battery Statues','Charging...')
sleep(3600)错误是:

程序不运行,上面写着:Fatal Error: program failed to execute script,
据我所知,pyinstaller没有将win10toast导入.exe文件,我也不知道如何使用它。
发布于 2020-05-24 20:10:59
好吧,我找到了一个奇怪的解决办法!刚刚编辑了这行:toaster.show_toast('Battery Statues','Battery Full.\nUnplug the Charger Please!',icon_path='')和所有相同的行,它现在正在运行,我认为库有一些bug。
发布于 2020-09-17 03:29:50
检查这个QA PyInstaller file fails to execute script - DistributionNotFound
中创建一个新的py文件
..\Lib\site-packages\PyInstaller\hooks
hook-win10toast.py其内容应是:
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('win10toast')https://stackoverflow.com/questions/61989633
复制相似问题