Well, I am making a personal project, for this project, I need to run a python script every time on the computer, and this script needs to start when the computer is turned on, for this, I used PyInstaller to turn the script in a “.exe” file, but an error is shown. Python Code, filename; “teste.py”:
import pynotifier pynotifier.Notification( "TESTE", # Translate: Test "ISSO É APENAS UM TESTE", # Translate: This is just a test 6 ).send()
this code just show me a notification, I turned it into a “.exe” file with this code:
pyinstaller --onefile --nowindowed teste.py
when I execute it, turns the python file into a exe file normally, but when I execute it, it shows me this message:
Exception in thread Thread-1: Traceback (most recent call last): File "threading.py", line 917, in _bootstrap_inner File "threading.py", line 865, in run File "win10toast__init__.py", line 93, in _show_toast File "pkg_resources__init__.py", line 1144, in resource_filename File "pkg_resources__init__.py", line 357, in get_provider File "pkg_resources__init__.py", line 900, in require File "pkg_resources__init__.py", line 786, in resolve pkg_resources.DistributionNotFound: The 'win10toast' distribution was not found and is required by the application
for more information, this is the code inside the PyNotifier module, since it has no documentation on the web:
init.py file:
from .pynotifier import Notification
version.py file:
VERSION = (0, 1, 1) __version__ = '.'.join(map(str, VERSION))
pynotifier.py file:
#!/usr/bin/env python # -*- coding: utf-8 -*- # PyNotifier # Copyright (c) 2018 Yuriy Lisovskiy # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. __all__ = ['Notification'] # standard library import platform # class to run notification class Notification: # urgency level URGENCY_LOW = 'low' URGENCY_NORMAL = 'normal' URGENCY_CRITICAL = 'critical' # 'title' - a title of notification # 'description' - more info about the notification # 'duration' - notification timeout in seconds # 'urgency' - notification urgency level # 'icon_path' - path to notification icon file def __init__(self, title, description, duration=5, urgency=URGENCY_LOW, icon_path=None): if urgency not in [self.URGENCY_LOW, self.URGENCY_NORMAL, self.URGENCY_CRITICAL]: raise ValueError('invalid urgency was given: {}'.format(urgency)) self.__WINDOWS = 'Windows' self.__LINUX = 'Linux' self.__title = title self.__description = description self.__duration = duration self.__urgency = urgency self.__icon_path = icon_path self.__is_windows = False # 'send' - sends notification depending on system def send(self): system = platform.system() if self.__LINUX in system: self.__send_linux() elif self.__WINDOWS in system: self.__send_windows() else: raise SystemError('notifications are not supported for {} system'.format(system)) # '__send_linux' - sends notification if running on Linux system def __send_linux(self): import subprocess command = [ 'notify-send', '{}'.format(self.__title), '{}'.format(self.__description), '-u', self.__urgency, '-t', '{}'.format(self.__duration * 1000) ] if self.__icon_path is not None: command += ['-i', self.__icon_path] subprocess.call(command) # '__send_windows' - sends notification if running on Windows system def __send_windows(self): try: import win10toast win10toast.ToastNotifier().show_toast( threaded=True, title=self.__title, msg=self.__description, duration=self.__duration, icon_path=self.__icon_path ) except ImportError: raise ImportError('notifications are not supported, can't import necessary library')
Please help me guys :|
Advertisement
Answer
Try this library’s
import plyer.platforms.win.notification from plyer import notification