[英]Issue with plyer library of python when creating a executable using pyinstaller
I am trying to generate a notification in windows using plyer library in python.我正在尝试使用 python 中的 plyer 库在 windows 中生成通知。 It works fine when the python script is run.运行 python 脚本时,它工作正常。 But when I try to create an executable file using pyinstaller and run the executable I keep getting this error但是当我尝试使用 pyinstaller 创建可执行文件并运行可执行文件时,我不断收到此错误
Traceback (most recent call last):
File "site-packages\plyer\utils.py", line 96, in _ensure_obj
ModuleNotFoundError: No module named 'plyer.platforms'
Traceback (most recent call last):
File "in_time.py", line 131, in <module>
File "site-packages\plyer\facades\notification.py", line 84, in notify
File "site-packages\plyer\facades\notification.py", line 90, in _notify
NotImplementedError: No usable implementation found!
This is the snippet of the code这是代码片段
from plyer import notification
notification.notify(
title='9 hours Completed',
message='You have successfully completed 9hrs for the day',
app_name='In Time App',
app_icon='Time3.ico'
)
使用pyinstaller创建可执行文件时,将其添加到命令:
--hidden-import plyer.platforms.win.notification
add following hidden import to spec file将以下隐藏导入添加到规范文件
a = Analysis(
...
hiddenimports=['plyer.platforms.win.notification'],
...
pyinstaller --onefile --hidden-import plyer.platforms.linux.notification filename.py
if you are using linux如果您使用的是 linux
plyer.platforms.win.notification
if you are using win There are also ios, macos, android platforms available so if you are using that, you may want to use those.如果您使用的是 win 还有可用的 ios、macos、android 平台,所以如果您正在使用它,您可能想要使用它们。 If it doesn't work then you may want to check the plyer.platforms.<your_flatform> directory and see if notifications.py is existing or not.如果它不起作用,那么您可能需要检查 plyer.platforms.<your_flatform> 目录并查看 notification.py 是否存在。
I am using Windows and the solution with hiddenimports didn't work for me.我正在使用 Windows 和 hiddenimports 的解决方案对我不起作用。
There's an other solution by copying the plyer package from python site_packages to the application directory as described here: https://stackoverflow.com/a/64448486/11362192还有另一种解决方案,方法是将 plyer package 从 python site_packages 复制到应用程序目录,如下所述: Z5E056C500A1C4B6A7110B50D807BADE645Z://stackoverflow.com/1/3
The copying of this package can also be automated.此 package 的复制也可以自动进行。 To do this, add the original path to the plyer package as datas to the spec file:为此,请将 plyer package 的原始路径作为数据添加到规范文件中:
site_packages_dir = 'C:/Python/Python310/Lib/site-packages/'
a = Analysis(
...
datas=[(site_packages_dir+'plyer', './plyer')],
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.