bkbilly / lnxlink

🖥 Effortlessly manage your Linux machine using MQTT.

Home Page:https://bkbilly.gitbook.io/lnxlink

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue with Fedora 39

aqwserf opened this issue · comments

What type of installation are you running?

Desktop

Which Linux OS are you using?

Fedora 39

Which version of LNXLink has the issue?

2023.11.0

The problem

After upgrading to Fedora 39, I had this issue, probably because of Python 3.12:

Traceback (most recent call last):
  File "/home/user/.local/bin/lnxlink", line 5, in <module>
    from lnxlink.__main__ import main
  File "/home/user/.local/lib/python3.12/site-packages/lnxlink/__main__.py", line 20, in <module>
    from .system_monitor import MonitorSuspend, GracefulKiller
  File "/home/user/.local/lib/python3.12/site-packages/lnxlink/system_monitor.py", line 11, in <module>
    from gi.repository import GLib
ImportError: cannot import name 'GLib' from 'pgi.repository' (/home/user/.local/lib/python3.12/site-packages/pgi/repository/__init__.py)

However, after digging a bit, I found that this changes in system_monitor.py did the trick:

#import pgi
import gi

#pgi.install_as_gi()

I don't have the full understanding of what's going on under the hood nor the time to make a PR but feel free to adapt if needed :)

Logs

No response

I've pushed an update for fixing this issue.
I haven't installed fedora 39 to test it, but it should work.

This method is responsible for monitoring when the Linux PC is about to shutdown or sleep by checking the dbus signals.

Awesome! Will test on the next release (or before if I have time) and let you know. Thanks

Still having the same issue and traceback on Fedora 39 after trying out the master branch. I'll post here if I figure it out.

This patch makes things work on F39. Seems the pgi package is no longer maintained and gi is the recommended one:
https://stackoverflow.com/questions/44213921/python-3-installing-gi-package-with-pip
https://pygobject.readthedocs.io/en/latest/

diff --git a/lnxlink/system_monitor.py b/lnxlink/system_monitor.py
index e41cb79..60617ce 100644
--- a/lnxlink/system_monitor.py
+++ b/lnxlink/system_monitor.py
@@ -10,13 +10,6 @@ from dbus.mainloop.glib import DBusGMainLoop
 
 logger = logging.getLogger("lnxlink")
 
-try:
-    import pgi
-
-    pgi.install_as_gi()
-except ImportError:
-    logger.error("Can't use PGI: %s", traceback.format_exc())
-
 from gi.repository import GLib
 
 

Hi @bkbilly . I confirm @pcsrule words, it's unfortunately not working with the patch 5c597a7.
Reverting back to gi works again

@pcsrule said that this patch works for him.

It will show up the traceback as an error on boot, but other than I believe that you won't have any issues, so @aqwserf what is the problem?
Could you send me some more information about it?

@bkbilly I believe @pcsrule says that his patch is working:

This patch makes things work on F39. Seems the pgi package is no longer maintained and gi is the recommended one: https://stackoverflow.com/questions/44213921/python-3-installing-gi-package-with-pip https://pygobject.readthedocs.io/en/latest/

diff --git a/lnxlink/system_monitor.py b/lnxlink/system_monitor.py
index e41cb79..60617ce 100644
--- a/lnxlink/system_monitor.py
+++ b/lnxlink/system_monitor.py
@@ -10,13 +10,6 @@ from dbus.mainloop.glib import DBusGMainLoop
 
 logger = logging.getLogger("lnxlink")
 
-try:
-    import pgi
-
-    pgi.install_as_gi()
-except ImportError:
-    logger.error("Can't use PGI: %s", traceback.format_exc())
-
 from gi.repository import GLib
 
 

But this is actually weird: I tried your patch again (downloading instead of making the modifications myself), and now it's working, so maybe a wrong copy/paste...

I guess we can close this issue.

Thanks again for the quick patch!

I'm happy that it worked for both of you!

@bkbilly I hadn't had the time and wanted to test it a little longer but the fix you proposed in fact doesn't work for me.
But this one does the job:

try:
    #import pgi
    import gi

    #pgi.install_as_gi()
except ImportError:
    logger.error("Can't use PGI, so GI is used instead...")

I don't have the skills to tell why gi works while pgi doesn't but if you need some help or if I can help you debug this one, feel free to reach out!

Thanks

P.S: btw, here's the log when I run your code:

Traceback (most recent call last):
  File "/home/guik/.local/bin/lnxlink", line 5, in <module>
    from lnxlink.__main__ import main
  File "/home/user/.local/lib/python3.12/site-packages/lnxlink/__main__.py", line 22, in <module>
    from .system_monitor import MonitorSuspend, GracefulKiller
  File "/home/user/.local/lib/python3.12/site-packages/lnxlink/system_monitor.py", line 16, in <module>
    pgi.install_as_gi()
    ^^^
NameError: name 'pgi' is not defined. Did you mean: 'gi'? 

Based on your logging, it seems like you are running an older version of LNXlink. When the app starts, it tells you about it's version.

  1. Could you try installing the latest version to test it again?
  2. Does the app stop after this error or does it continue as normal?

Thanks for the prompt response @bkbilly.

For some reason, if I use your code, the version indeed doesn't show up, even if I'm on the latest version. But with my modification, it does. Here's what I have:

  1. with your code
$ head -20 /home/user/.local/lib/python3.12/site-packages/lnxlink/system_monitor.py
"""Monitors for shutdown/sleep events"""

import threading
import signal
import logging

import dbus
from dbus.mainloop.glib import DBusGMainLoop

logger = logging.getLogger("lnxlink")

try:
    import pgi
    #import gi

    pgi.install_as_gi()
except ImportError:
    logger.error("Can't use PGI, so GI is used instead...")

from gi.repository import GLib                                                                                                                                                           /0.0s

$ /home/user/.local/bin/lnxlink -c /home/guik/.config/lnxlink/config.yaml      
Traceback (most recent call last):
  File "/home/user/.local/bin/lnxlink", line 5, in <module>
    from lnxlink.__main__ import main
  File "/home/user/.local/lib/python3.12/site-packages/lnxlink/__main__.py", line 22, in <module>
    from .system_monitor import MonitorSuspend, GracefulKiller
  File "/home/user/.local/lib/python3.12/site-packages/lnxlink/system_monitor.py", line 20, in <module>
    from gi.repository import GLib
ImportError: cannot import name 'GLib' from 'pgi.repository' (/home/user/.local/lib/python3.12/site-packages/pgi/repository/__init__.py)                                                 /0.3s
  1. with mine
$ head -20 /home/user/.local/lib/python3.12/site-packages/lnxlink/system_monitor.py
"""Monitors for shutdown/sleep events"""

import threading
import signal
import logging

import dbus
from dbus.mainloop.glib import DBusGMainLoop

logger = logging.getLogger("lnxlink")

try:
    #import pgi
    import gi

    #pgi.install_as_gi()
except ImportError:
    logger.error("Can't use PGI, so GI is used instead...")

from gi.repository import GLib                                                                                                                                                           /0.0s

$ /home/user/.local/bin/lnxlink -c /home/user/.config/lnxlink/config.yaml      
INFO:lnxlink:LNXlink 2023.12.1, Python 3.12.0
INFO:lnxlink:Loaded addons: audio_select, idle, media, microphone_used, notify, update, keep_presence_lnxlink
INFO:lnxlink:Connected to MQTT with code 0
^CINFO:lnxlink:stopped gracefully
INFO:lnxlink:Power Down detected.
INFO:lnxlink:Disconnected from MQTT.                                                            

Hope this helps!

It seems that the latest versions of python, the PGI package is not needed, but I'll have to look into it.
I'll make some tests and I might remove it on the future version of the app from the dependencies and from the system_monitor file.

I've released the 2023.12.2 version which fixes this issue.

Confirm this is working. Thanks @bkbilly!