[英]Pyinstaller wont import a pkg into the exe file / failed to execute the script
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:我想用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)
and program doesnt run, it says: Fatal Error: program failed to execute script,
并且程序没有运行,它说:
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.据我了解,pyinstaller 没有将
win10toast
导入到 .exe 文件中,我不知道如何使用它。
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.好的,我找到了一种奇怪的解决方法:刚刚编辑了以下行:
toaster.show_toast('Battery Statues','Battery Full.\nUnplug the Charger Please,',icon_path='')
和所有相同的行,它正在运行现在,我认为图书馆有一些错误。
Check this QA PyInstaller file fails to execute script - DistributionNotFound检查此 QA PyInstaller 文件无法执行脚本 - DistributionNotFound
You need to create a new py file in您需要在其中创建一个新的 py 文件
..\Lib\site-packages\PyInstaller\hooks
hook-win10toast.py
The content should be:内容应该是:
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('win10toast')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.