I want to create an executable program with pyinstaller , but after creating the file successfully, and when I want to run the file, I have the error, this is my code:
# -*- 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)
and program doesnt run, it says: Fatal Error: program failed to execute script,
as I understood, pyinstaller didn't import the win10toast
to the.exe file, and I don't know how to work with it.
ok, i found a strange way to solve: just edited this lines: toaster.show_toast('Battery Statues','Battery Full.\nUnplug the Charger Please,',icon_path='')
and all of the same lines, its running now, i think library has some bugs.
Check this QA PyInstaller file fails to execute script - DistributionNotFound
You need to create a new py file in
..\Lib\site-packages\PyInstaller\hooks
hook-win10toast.py
The content should be:
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('win10toast')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.