kraanzu/smassh

[BUG] ModuleNotFoundError: No module named 'preferredsoundplayer'

bttger opened this issue ยท 13 comments

Describe the bug ๐Ÿ›
I've installed termtpye via the AUR. I had to choose between the repository or the AUR package for python-playsound and chose the repository version. When starting termtype I get the following error:

Traceback (most recent call last):
  File "/usr/bin/termtyper", line 5, in <module>
    from termtyper.__init__ import main
  File "/usr/lib/python3.10/site-packages/termtyper/__init__.py", line 1, in <module>
    from .ui import TermTyper
  File "/usr/lib/python3.10/site-packages/termtyper/ui/__init__.py", line 1, in <module>
    from .tui import TermTyper
  File "/usr/lib/python3.10/site-packages/termtyper/ui/tui.py", line 12, in <module>
    from termtyper.ui.settings_options import MenuSlide
  File "/usr/lib/python3.10/site-packages/termtyper/ui/settings_options.py", line 11, in <module>
    from termtyper.ui.widgets import banners
  File "/usr/lib/python3.10/site-packages/termtyper/ui/widgets/__init__.py", line 2, in <module>
    from .race_hud import RaceHUD
  File "/usr/lib/python3.10/site-packages/termtyper/ui/widgets/race_hud.py", line 10, in <module>
    from ...utils import Parser
  File "/usr/lib/python3.10/site-packages/termtyper/utils/__init__.py", line 3, in <module>
    from .play_keysound import play_keysound, play_failed
  File "/usr/lib/python3.10/site-packages/termtyper/utils/play_keysound.py", line 2, in <module>
    from preferredsoundplayer import playsound
ModuleNotFoundError: No module named 'preferredsoundplayer'

To Reproduce ๐Ÿฃ
See bug description.

Expected behavior ๐Ÿค”
It should work after installing the package.

Screenshots ๐Ÿง
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information): ๐Ÿค–

  • OS: Manjaro

Additional context ๐Ÿ“
Add any other context about the problem here.

Yeah about that, preferred-sound-player is not in the AUR.
So I am not so sure how to approach this.
Ig I'll add a pip command in pkgbuild, tho I don't prefer this :(

In the meantime you can install it by this command:

pip install preferredsoundplayer

Why is this a mandatory module which leads to a crash when missing instead of being optional with a note when booting?

Based on the name this module looks like bloat for those who don't care about having sound be played by python.

Based on the name this module looks like bloat for those who don't care about having sound be played by python.

I agree. I don't need sound.

Based on the name this module looks like bloat for those who don't care about having sound be played by python.

I was using playsound but somehow it's not working on linux anymore... So the alternative..... which seemed to work just fine

I agree. I don't need sound.

Hmm, ig I'll add a parameter such as -q or -quiet which will run termtyper in quiet mode?

Requiring a parameter to not crash doesn't feel good to me. Consider automatically detecting the lack of sound modules and entering mute mode on top of having opt-in or opt-out for sound.

Requiring a parameter to not crash doesn't feel good to me

No I am not suggesting this as an alternative to crashing. Crashing was due to the reason that the sound module was not packaged for the AUR.

Consider automatically detecting the lack of sound modules and entering mute mode on top of having opt-in or opt-out for sound.

I don't see how this is feasible. The sound gets installed along with termtyper.
If it throws an error internally, I can use try-catch statements to just ignore the error.

As far as I know, python does not have method for 'optional' installation (something like rust does)

Crashing was due to the reason that the sound module was not packaged for the AUR.

I got this same crash with git clone, cd, install, cd ~, termtyper on Ubuntu 22.04. It's not AUR specific.

I see. Can you add any pictures?

I initially fixed this with the suggested pip install preferredsoundplayer, I've lost my shell log due to having rebooted after running it but if I now run these I get the following.

โ”Œโ”€[drjaska@perkele] - [~] - [2022-07-19 08:50:36]
โ””โ”€[0] <> pip uninstall preferredsoundplayer
Found existing installation: preferredsoundplayer 0.0.5
Uninstalling preferredsoundplayer-0.0.5:
  Would remove:
    /home/drjaska/.local/lib/python3.10/site-packages/preferredsoundplayer-0.0.5.dist-info/*
    /home/drjaska/.local/lib/python3.10/site-packages/preferredsoundplayer/*
Proceed (Y/n)? 
  Successfully uninstalled preferredsoundplayer-0.0.5
โ”Œโ”€[drjaska@perkele] - [~] - [2022-07-19 08:50:59]
โ””โ”€[0] <> termtyper
Traceback (most recent call last):
  File "/home/drjaska/.local/bin/termtyper", line 5, in <module>
    from termtyper.__init__ import main
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/__init__.py", line 1, in <module>
    from .ui import TermTyper
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/ui/__init__.py", line 1, in <module>
    from .tui import TermTyper
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/ui/tui.py", line 12, in <module>
    from termtyper.ui.settings_options import MenuSlide
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/ui/settings_options.py", line 11, in <module>
    from termtyper.ui.widgets import banners
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/ui/widgets/__init__.py", line 2, in <module>
    from .race_hud import RaceHUD
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/ui/widgets/race_hud.py", line 10, in <module>
    from ...utils import Parser
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/utils/__init__.py", line 3, in <module>
    from .play_keysound import play_keysound, play_failed
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/utils/play_keysound.py", line 2, in <module>
    from preferredsoundplayer import playsound
ModuleNotFoundError: No module named 'preferredsoundplayer'
โ”Œโ”€[drjaska@perkele] - [~] - [2022-07-19 08:51:12]
โ””โ”€[1] <> 

I can at a later date say if things differ after a clean system install as I'm going to reformat my drive.

I initially fixed this with the suggested pip install preferredsoundplayer, I've lost my shell log due to having rebooted after running it but if I now run these I get the following.

โ”Œโ”€[drjaska@perkele] - [~] - [2022-07-19 08:50:36]
โ””โ”€[0] <> pip uninstall preferredsoundplayer
Found existing installation: preferredsoundplayer 0.0.5
Uninstalling preferredsoundplayer-0.0.5:
  Would remove:
    /home/drjaska/.local/lib/python3.10/site-packages/preferredsoundplayer-0.0.5.dist-info/*
    /home/drjaska/.local/lib/python3.10/site-packages/preferredsoundplayer/*
Proceed (Y/n)? 
  Successfully uninstalled preferredsoundplayer-0.0.5
โ”Œโ”€[drjaska@perkele] - [~] - [2022-07-19 08:50:59]
โ””โ”€[0] <> termtyper
Traceback (most recent call last):
  File "/home/drjaska/.local/bin/termtyper", line 5, in <module>
    from termtyper.__init__ import main
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/__init__.py", line 1, in <module>
    from .ui import TermTyper
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/ui/__init__.py", line 1, in <module>
    from .tui import TermTyper
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/ui/tui.py", line 12, in <module>
    from termtyper.ui.settings_options import MenuSlide
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/ui/settings_options.py", line 11, in <module>
    from termtyper.ui.widgets import banners
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/ui/widgets/__init__.py", line 2, in <module>
    from .race_hud import RaceHUD
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/ui/widgets/race_hud.py", line 10, in <module>
    from ...utils import Parser
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/utils/__init__.py", line 3, in <module>
    from .play_keysound import play_keysound, play_failed
  File "/home/drjaska/.local/lib/python3.10/site-packages/termtyper/utils/play_keysound.py", line 2, in <module>
    from preferredsoundplayer import playsound
ModuleNotFoundError: No module named 'preferredsoundplayer'
โ”Œโ”€[drjaska@perkele] - [~] - [2022-07-19 08:51:12]
โ””โ”€[1] <> 

I can at a later date say if things differ after a clean system install as I'm going to reformat my drive.

This is the same traceback that I got when I opened this issue.

Copy the following and replace it -->>> "play_keysound.py"

from threading import Thread
from playsound import playsound
from os import path

from ..utils import Parser

SOUNDS_LOC = path.join(path.dirname(file), "..", "sounds")

def get_sound_location(sound: str) -> str:
return str(path.join(SOUNDS_LOC, f"{sound}.wav"))

def play(sound_file: str) -> None:
Thread(target=playsound, args=(sound_file,), daemon=True).start()

def play_keysound() -> None:
sound = Parser().get_theme("sound")
sound_file = get_sound_location(sound)
playsound(sound_file)

def play_failed() -> None:
sound_file = get_sound_location("failed")
playsound(sound_file)

My bad, I just ran the test file without actually installing it with pip..
Sorry for the inconvenience ๐Ÿ˜ž

I've pushed the updates

The error has been fixed and a quiet mode flag feature has been added in this commit