我想用 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文件,而且我也不知道如何使用它。
答案 0 :(得分:1)
好的,我找到了一种奇怪的解决方法!
刚刚编辑了以下几行:
toaster.show_toast('Battery Statues','Battery Full.\nUnplug the Charger Please!',icon_path='')
并且所有相同的代码行现在都在运行,我认为库有一些错误。
答案 1 :(得分:0)
检查此质量检查 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')