Reputation: 77
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.
Upvotes: 0
Views: 442
Reputation: 11
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')
Upvotes: 0
Reputation: 77
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.
Upvotes: 1