![](/img/trans.png)
[英]How to turn a python file to an exe file, so that the code can be masked
[英]How can I turn a python file into a exe file withou this error
嗯,我在做一個個人項目,對於這個項目,我需要每次在電腦上運行一個python腳本,並且這個腳本需要在電腦開機的情況下啟動,為此我使用了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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.