Python notification not working after compiling - python

My app is doing something weird. When the app sends a notification, it works just fine in the source code when its run with vs code. But after compiling with pyinstaller, suddenly it doesn't work.
code:
import plyer
notification.notify(title = 'Message', message = Message, app_icon = 'Ringer-Icon.ico', timeout = 10,)
After testing a separate file with this i go this error:
Traceback (most recent call last):
File "plyer\utils.py", line 93, in _ensure_obj
ModuleNotFoundError: No module named 'plyer.platforms'
Traceback (most recent call last):
File "notification test.py", line 3, in <module>
File "plyer\facades\notification.py", line 79, in notify
File "plyer\facades\notification.py", line 88, in _notify
NotImplementedError: No usable implementation found!
[12520] Failed to execute script 'notification test' due to unhandled exception!

This question was already answered:
Issue with plyer library of python when creating a executable using pyinstaller
Plyer "NotImplementedError: No usable implementation found!" while sending notifications in a .exe
You can specify the platform-dependent dependency(s) as --hidden-import when packaging with PyInstaller.
E.g. for the windows implementation use:
--hidden-import plyer.platforms.win.notification
Plyer supports notifications (with implementations) on following platforms except iOS (their namespace/folder name in parentheses):
Android (android)
Windows (win)
OS X (macosx)
Linux (linux)
See also:
Using PyInstaller to Easily Distribute Python Applications – Real Python

Related

Getting an import error on android while code works on windows (kivy)

I'm building an app using kivy/python. I created an apk using buildozer. On windows my code runs perfectly but when I run the apk on my android device it immediately crashes. I ran adb logcat to find the error and I think I've found the relevant bit:
I python : Traceback (most recent call last):
I python : File "/home/casper/Desktop/MyApp/.buildozer/android/app/main.py", line 17, in <module>
I python : File "/home/casper/Desktop/MyApp/.buildozer/android/app/price.py", line 8, in <module>
I python : ModuleNotFoundError: No module named 'requests'
I python : Python for android ended.
This seems weird to me because everything works when I run it on my laptop. Do I need to install requests in another directory or something? Thanks!
yes your code will work perfectly fine while testing on your windows, this is because python has the module 'requests' . But on compiling to apk , you will run into errors because python for android does not have the 'requests' module. .you will need to check alternative libraries that are supported by 'python for android'

Shipping PyGObject/GTK+ app on Windows with MingW

I'm using PyGObject/GTK+ with Python3.7 on Windows and is worried about how to package my app. With official Python ecosystem, it's easy to use freezers and venvs. However, the PyGObject and GTK+ on Windows requires the MingW environment to run.
Does this mean that I have to package the entire MingW, along with GTK+?
How should I freeze the app?
Since no one cares soon enough, I'll report my findings here. The short answer, as of the date I write this post, is: The PyGObject eco-system is not commercial-ready on Windows, although nothing stops you from shipping a functional app.
The deal-breaker is the lack of functional freezers on Windows for PyGOBject. So you can't really ship a closed-source commercial product with it (although one could argue that the entire Python eco-system is not made for that). The freezers that I tried:
The officially recommended PyInstaller right now does not install with the officially recommended msys/MingGW universe; Even after building PyInstaller from source, the frozen .exe crashes with complaints about missing modules. Below is the crash report from a hello-world app.
$ app.exe
[8340] mod is NULL - structTraceback (most recent call last):
File "C:/Apps/msys64/mingw64/lib/python3.7/struct.py", line 13, in <module>
from _struct import *
ModuleNotFoundError: No module named '_struct'
[8340] mod is NULL - pyimod02_archiveTraceback (most recent call last):
File "C:/Apps/msys64/mingw64/lib/python3.7/site-packages/pyinstaller-3.5-py3.7.egg/PyInstaller/loader/pyimod02_archive.py", line 28, in <module>
import struct
ModuleNotFoundError: No module named 'struct'
[8340] mod is NULL - pyimod03_importersTraceback (most recent call last):
File "C:/Apps/msys64/mingw64/lib/python3.7/site-packages/pyinstaller-3.5-py3.7.egg/PyInstaller/loader/pyimod03_importers.py", line 24, in <module>
from pyimod02_archive import ArchiveReadError, ZlibArchiveReader
ModuleNotFoundError: No module named 'pyimod02_archive'
Traceback (most recent call last):
File "site-packages/pyinstaller-3.5-py3.7.egg/PyInstaller/loader/pyiboot01_bootstrap.py", line 15, in <module>
ModuleNotFoundError: No module named 'pyimod03_importers'
[8340] Failed to execute script pyiboot01_bootstrap
cx_Freeze, another prominent alternative, does not build/install on MingW, either. You end up with gcc woes, no matter how many gcc variants you install.
py2exe is now abandonware since Python 3.4.
Since a PyGObject app still runs with MinGW python, it's not impossible to ship such an app for Windows. But that means you'll go with the big baggage and figure out a way to pack everything yourself. Let alone maintain the whole mess. Mind you that the procedure will be different on Mac if your app is cross-platform. PyInstaller works on Mac according to my test.
QuodLibet provides an example of how to ship an open-source software based on PyGObject. Unfortunately, as of today, the upstream's packaging procedure fails at the build.sh run on my Windows 10:
copying data/quodlibet.zsh -> E:\_dev\quodlibet\win_installer\_build_root\mingw64\share\zsh\vendor-completions\_quodlibet
Traceback (most recent call last):
File "E:/_dev/quodlibet/win_installer/misc/depcheck.py", line 141, in <module>
main(sys.argv)
File "E:/_dev/quodlibet/win_installer/misc/depcheck.py", line 130, in main
libs = get_things_to_delete(sys.prefix)
File "E:/_dev/quodlibet/win_installer/misc/depcheck.py", line 108, in get_things_to_delete
for lib in get_dependencies(path):
File "E:/_dev/quodlibet/win_installer/misc/depcheck.py", line 66, in get_dependencies
data = data.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa3 in position 72: invalid start byte
This turns out to be an easy fix: locale issue on non-UTF8 Windows.
A trivial patch would be replacing "utf-8" with locale.getdefaultlocale(). After that, the build succeeds.
However, the global distribution issues remain challenging:
Bloated pipeline: The officially recommended msys2 build system basically drags the entire GNOME universe and much of the Python universe to your machine, while you may already have a Python environment on your native Windows. It proves hard to cherry-pick the necessary dependencies among this whole pile of stuff.
Extra C pipeline required to build the executable. To build a Windows executable without a freezer, you must create your app as a Python package (big hassle), install it to your msys2-Python site-packages (another setup.py hassle), and then build a wrapper C application using the Python C API (opaque hassle). The process is not transparent, especially when Python packaging system is sensitive to working directory and path differences. Launching the executable can easily go wrong without much debug info.
Manual stripping. As mentioned above, you must manually cherry-pick dependencies or your app would be shipped with basically the entire msys2/MinGW universe that's worth 100MB+ for a hello-world app.

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. 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'
)
When creating the executable with pyinstaller, add this to the command:
--hidden-import plyer.platforms.win.notification
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')],
...
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
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. 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.

JPype won't compile properly

So I am having trouble compiling a very simple python script using JPype.
My code goes like:
from jpype import *
startJVM(getDefaultJVMPath(), "-ea")
java.lang.System.out.println("hello world")
shutdownJVM()
and when I run it I receive an error saying:
Traceback (most recent call last): File "test.py", line 2, in
<module>
startJVM(getDefaultJVMPath(), "-ea") File "/usr/lib/pymodules/python2.7/jpype/_core.py", line 44, in startJVM
_jpype.startup(jvm, tuple(args), True) RuntimeError: Unable to load DLL [/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so], error =
/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so: cannot open shared
object file: No such file or directory at
src/native/common/include/jp_platform_linux.h:45
I'm stuck and I really need help. Thanks!
I had the same problem
RuntimeError: Unable to load DLL [/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so], error = /usr/java/jre1.5.0_05/lib/i386/client/libjvm.so: cannot open shared object file: No such file or directory at src/native/common/include/jp_platform_linux.h:45
In my case wrong JAVA_HOME path was set
/profile/etc
export JAVA_HOME
JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
PATH="$JAVA_HOME/bin:$PATH"
export PATH
The work around is to define the full path directly in the call to the JVM:
from jpype import *
startJVM('/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/MacOS/libjli.dylib', "-ea", "-Djava.class.path=/tmp/Jpype/sample")
java.lang.System.out.println("Hello World!!")
shutdownJVM()
Original text:
Similar issues when trying to run JPype on MacOS El Capitan. I could
not figure out how to coax the _darwin.py code finding the correct JVM
location, despite the JAVA_HOME system variable being set properly.
Caveat cursor, trying to run the above code in the Spyder IPython console did not produce any output, but the normal Console would.

nxt-py no backends error

i am trying to run one of the example scripts for nxt py library using pyusb. whenever i try to run the examples i get the following error:
USB module unavailable, not searching there
Bluetooth module unavailable, not searching there
Traceback (most recent call last):
File "C:\Documents and Settings\*\Desktop\nxt-python-2.2.1\examples\mary.py", line
15, in <module>
b = nxt.locator.find_one_brick()
File "C:\Python27\lib\site-packages\nxt\locator.py", line 112, in find_one_brick
for s in find_bricks(host, name, silent, method):
File "C:\Python27\lib\site-packages\nxt\locator.py", line 80, in find_bricks
raise NoBackendError("No selected backends are available! Did you install the comm
modules?")
NoBackendError: No selected backends are available! Did you install the comm modules?
i have no idea how to fix this and i was wondering if there was any other way than just switching to bluetooth?
USB and Bluetooth are unavailable. You need to install python modules to be able to run examples.
Here is installation guide,
choose your operating system.
For me (mac os x) works only fantomusb. Also I needed to set attributes for brick locator to find it trought fantomusb.
b = nxt.locator.find_one_brick(name="NXT", strict=True, method=nxt.locator.Method(bluetooth=False, fantomusb=True, fantombt=False, usb=False))

Categories

Resources