kraanzu / smassh

Smassh your Keyboard, TUI Edition
GNU General Public License v3.0
1.41k stars 50 forks source link

[BUG] ModuleNotFoundError: No module named 'preferredsoundplayer' #19

Closed bttger closed 2 years ago

bttger commented 2 years ago

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): 🤖

Additional context 📝 Add any other context about the problem here.

kraanzu commented 2 years ago

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
drjaska commented 2 years ago

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.

bttger commented 2 years ago

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.

kraanzu commented 2 years ago

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?

drjaska commented 2 years ago

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.

kraanzu commented 2 years ago

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)

drjaska commented 2 years ago

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.

kraanzu commented 2 years ago

I see. Can you add any pictures?

drjaska commented 2 years ago

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.

bttger commented 2 years ago

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.

liric28 commented 2 years ago

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)

kraanzu commented 2 years ago

My bad, I just ran the test file without actually installing it with pip.. Sorry for the inconvenience :disappointed:

I've pushed the updates

kraanzu commented 2 years ago

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