如何将 python 文件转换为 exe 文件而不出现此错误

How can I turn a python file into a exe file withou this error

嗯,我正在做一个个人项目,对于这个项目,我需要每次在电脑上运行一个python脚本,并且这个脚本需要在电脑开机时启动on,为此,我使用 PyInstaller 将脚本转换为“.exe”文件,但显示错误。 Python代码,文件名; “teste.py”:

import pynotifier

pynotifier.Notification(
    "TESTE",  # Translate: Test
    "ISSO É APENAS UM TESTE",  # Translate: This is just a test
    6
).send()

这段代码只是给我一个通知,我用这段代码把它变成了一个“.exe”文件:

pyinstaller --onefile --nowindowed teste.py

当我执行它时,将 python 文件正常转换为 exe 文件,但是当我执行它时,它显示以下消息:

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

有关更多信息,这是 PyNotifier 模块中的代码,因为它在 Web 上没有文档:

初始化.py文件:

from .pynotifier import Notification

版本.py文件:

VERSION = (0, 1, 1)
__version__ = '.'.join(map(str, VERSION))

pynotifier.py 文件:

#!/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')

请大家帮帮我:|

试试这个图书馆的

import plyer.platforms.win.notification
from plyer import notification