Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with plyer library of python when creating a executable using pyinstaller

Tags:

python

windows

I am trying to generate a notification in windows using plyer library in python. It works fine when the python script is run. But when I try to create an executable file using pyinstaller and run the executable I keep getting this error

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'
    )
like image 651
Ram Rohit Gannavarapu Avatar asked May 23 '19 19:05

Ram Rohit Gannavarapu


Video Answer


2 Answers

When creating the executable with pyinstaller, add this to the command:

--hidden-import plyer.platforms.win.notification
like image 181
mucomoc Avatar answered Nov 15 '22 05:11

mucomoc


I am using Windows and the solution with hiddenimports didn't work for me.

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

The copying of this package can also be automated. To do this, add the original path to the plyer package as datas to the spec file:

site_packages_dir = 'C:/Python/Python310/Lib/site-packages/'

a = Analysis(
   ...
   datas=[(site_packages_dir+'plyer', './plyer')],
   ...
like image 32
j4ggr Avatar answered Nov 15 '22 03:11

j4ggr