muammar / mkchromecast

Cast macOS and Linux Audio/Video to your Google Cast and Sonos Devices
http://mkchromecast.com
Other
2.21k stars 137 forks source link

Issues with Tray Application: ModuleNotFoundError: No module named 'imp' #464

Closed psmgeelen closed 4 months ago

psmgeelen commented 4 months ago

Hi there, As discussed in this [issue}(https://github.com/muammar/mkchromecast/issues/398) I noticed that when I installed mkchromecast, there were some issues, and it basically doesn't create the sound connector. I use Ubuntu 24.04 LTS and installed mkchromecast using apt. The traceback (see below for full traceback), denotes ModuleNotFoundError: No module named 'imp' which makes me wonder whether there might be a dependency issue. Also note that Ubuntu 24.04 LTS is now using python 3.12.4 for native python:

python3
Python 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

I also found when doing a Google search that this is a general issue with supporting python 3.12.

Summary:

Details: Specs, Logs and Traceback of error

Specs

inxi -SMG
System:
  Host: desktop-B550-Taichi Kernel: 6.8.0-31-generic arch: x86_64 bits: 64
  Desktop: GNOME v: 46.0 Distro: Ubuntu 24.04 LTS (Noble Numbat)
Machine:
  Type: Desktop Mobo: ASRock model: B550 Taichi serial: <superuser required>
    UEFI: American Megatrends LLC. v: P2.10 date: 02/24/2022
Graphics:
  Device-1: NVIDIA GA102 [GeForce RTX 3090] driver: nvidia v: 535.171.04
  Device-2: Logitech HD Pro Webcam C920 driver: snd-usb-audio,uvcvideo
    type: USB
  Display: x11 server: X.Org v: 21.1.11 with: Xwayland v: 23.2.6 driver: X:
    loaded: modesetting,nouveau,nvidia unloaded: fbdev,vesa
    gpu: nvidia,nvidia-nvswitch resolution: 1: 3440x1440~50Hz 2: N/A
  API: EGL v: 1.5 drivers: kms_swrast,nvidia,swrast
    platforms: gbm,x11,surfaceless,device
  API: OpenGL v: 4.6.0 compat-v: 4.5 vendor: nvidia mesa v: 535.171.04
    renderer: NVIDIA GeForce RTX 3090/PCIe/SSE2

Logs

When I run mkchromecast -t I can follow the logs, that yield the following:

 ~/.local/share/applications                                                                                                                                                                             11:12:00  ✖
/usr/bin/mkchromecast -t
Mkchromecast v0.3.9
Selected backend: /usr/bin/parec
Selected audio codec: mp3
Default bitrate used: 192k
Default sample rate used: 44100Hz.
Configuration file exists
Using defaults set there
Configuration file exists
Using defaults set there

List of Devices Available in Network:
-------------------------------------

Index   Types   Friendly Name
=====   =====   =============
0   Gcast   Keuken
1   Gcast   Tech
2   Gcast   Buro
3   Gcast   AllSpeakers
available_devices received
Configuration file exists
Using defaults set there
Available Media Streaming Devices [[0, 'Keuken', 'Gcast'], [1, 'Tech', 'Gcast'], [2, 'Buro', 'Gcast'], [3, 'AllSpeakers', 'Gcast']]
:::Threading::: Configuration file exists.
:::Threading::: Using defaults set there.
:::Threading backend::: parec.

At this stage I have selected some option, I get the same response for all 4 options:

Traceback:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/mkchromecast/tray_threading.py", line 90, in _play_cast_
    reload(mkchromecast.audio)
    ^^^^^^
UnboundLocalError: cannot access local variable 'reload' where it is not associated with a value

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/mkchromecast/tray_threading.py", line 92, in _play_cast_
    from imp import reload
ModuleNotFoundError: No module named 'imp'

Question

I would need some help, but I could definitely refactor this for the project if you want me too. I would need to know more about your process of forking and testing to ensure that my PR will be somewhat appropriate.

Feedback

This is my first time making an issue in this repo. Please let me know whether this format works for you :)

Thanks, I really appreciate your time!

xsdg commented 4 months ago

Thanks for the detailed report! I agree with you that switching from imp to importlib is probably the straightforward approach. It looks like importlib.reload was introduced in Python 3.4, so version support isn't something we need to worry about. I would also move the import to the top and just get rid of the conditional there.

The longer-term solution (which I've been working on, but still needs more work), is to get away from work being done at import (this is mostly done), and to introduce another mechanism to use updated settings (this still needs a fair bit of work)

psmgeelen commented 4 months ago

Hey @xsdg , should I create a PR for changing the imp to importlib for the time being? Or do you want to prioritize on the refactor that you mentioned? (If I can help with the refactor, please let me know :) )

xsdg commented 4 months ago

Yeah, it probably makes sense to do the importlib change for now.

I'll try to write up how the current architecture works and some options for settings updates later today (I'm in US Pacific Time, so that'll probably be 6 to 12 hours from now)

psmgeelen commented 4 months ago

I will create a PR tomorrow ;) Im CET (Germany).

xsdg commented 4 months ago

I forgot that I had already written up a preliminary bug. I just added a fair bit of context to give more of the story of how things started and where they need to go.

To add to that, the main reason that tray_threading.py attempts to re-import audio.py is to force the audio-pipeline to be restarted using up-to-date configuration settings, when those settings might have just been changed. In practice, I believe this is already broken, but it probably makes sense to keep the re-import happening for now just to avoid potentially stacking breakages that manifest differently across different codepaths.