ImportError: No module named playsound [solved]
See original GitHub issueThanks @Sangarshanan for the package. I was continuously getting ImportError
for playground
. After many trial and error , I figured out that I had to change two instances of python
to python3
since that’s how it’s called on my machine (Mac OS Catalina)
jazz.py
from .settings import current_dir
import os
import sys
import time
import signal
import traceback
import subprocess
def get_track_path(track):
track_path = os.path.join(current_dir, "tracks", track)
if os.path.exists(track_path):
return track_path
else:
return track
def kill_process(process):
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
class WaitingTrack(object):
"""Use on loooong scripts."""
def __init__(self, track=None):
self.track = track
def __call__(self, original_func):
def wrapped_function(*args):
track_path = get_track_path(self.track)
cmd = f"python3 {current_dir}/play.py {track_path}"
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid
)
try:
original_func(*args)
except KeyboardInterrupt:
kill_process(process)
finally:
kill_process(process)
return wrapped_function
class ErrorTrack(object):
"""Use on potential oopsies."""
def __init__(self, track=None, wait=None, ascii_err=False):
self.track = track
# Time (optional) will be infered by track length
self.wait = wait
# ascii_err (Optional) Print the exception as an ascii art
self.ascii_err = ascii_err
def __call__(self, original_func):
def wrapped_function(*args):
try:
original_func(*args)
except Exception as e:
track_path = get_track_path(self.track)
if self.ascii_err:
from pyfiglet import figlet_format
sys.stdout.write(figlet_format(e.__class__.__name__))
traceback.print_exc()
cmd = f"python3 {current_dir}/play.py {track_path}"
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid
)
if self.wait is None:
from .utils import track_length
time.sleep(track_length(track_path))
else:
time.sleep(self.wait)
finally:
kill_process(process)
return wrapped_function
I don’t know if anyone else also faced this issue. It’d be good if you can handle it better !
Thank you!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ImportError: no module named playsound - Stack Overflow
The best solution that worked for me is uninstalling playsound using pip uninstall playsound and then installing it again using pip install ...
Read more >import "playsound" could not be resolved from source - You.com
Answered on Oct 6, 2019. Just change from playsound import playsound to import playsound. Open side panel. ImportError no module named 'playsound'.
Read more >2021 How to Fix "No Module Named..." Error in Python
2021 How to Fix ImportError " No Module Named pkg_name" in Python! First, download the package using a terminal outside of python.
Read more >Sajal Tiwari on Twitter: "New error: ImportError: cannot import ...
Solutions: 1. Check file name.File name should not be a module name. 2. Rollback module to previous version. 3. Use pip3 or python...
Read more >How to fix "Unable to load sound" error with Python Playsound ...
I have found where the problem is. In the python3.7/site-packages/playsound.py file The developer has not checked for " " spaces in file path,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I don’t know if it does justice to your work @Sangarshanan but here’s the humble video demo - https://youtu.be/qkyQfIjvPmM
If you feel it’s worthy to be there, please feel free to. It’s my pleasure!