简体   繁体   English

使用 pyinstaller 创建可执行文件时 python 的 plyer 库出现问题

[英]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.

相关问题 使用 PyInstaller 时 plyer 的问题 - problem with plyer when using PyInstaller 使用 pyinstaller 创建 Python 可执行文件时未导入库 - Libraries not imported when creating a Python executable with pyinstaller 使用pyinstaller创建可执行文件时出错 - Error when creating executable file with pyinstaller 我使用pyinstaller创建了python可执行文件,但是执行可执行文件时不存在导入到.py脚本的模块 - I created a python executable by using pyinstaller, but the module imported to my .py script is not present when I execute executable Pyinstaller 没有创建可执行文件 - Pyinstaller not creating executable pyinstaller创建一个无用的可执行文件 - pyinstaller creating a useless executable 使用pyinstaller创建可执行文件时如何处理pyproj datadir / CRS错误 - How to handle pyproj datadir/CRS error when creating an executable using pyinstaller 使用 pyinstaller 创建 python windows 可执行文件时出现问题 - 创建、运行但立即退出 - Problem creating a python windows executable with pyinstaller - creates, runs but quits immediately 如何为 PyInstaller 可执行文件指定 Python 版本和库版本 - How to specify Python version and library versions for PyInstaller executable 使用pyinstaller在Linux中创建python可执行文件,无法在Windows计算机上运行 - Creating a python executable in Linux with pyinstaller, fails to run in a Windows machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM