Home > front end >  Why does invoking the playsound module cause my script to crash?
Why does invoking the playsound module cause my script to crash?

Time:04-17

The code:

import time
import playsound

print('Study period in minutes?')
studyMin = float(input())
print('Break period in minutes?')
breakMin = float(input())
print('How many repetitions?')
repe = int(input())

for i in range(repe):
    print('You have '   str(repe)   ' repetitions left!')
    playsound('repetition.wav')
    print('Study!')
    time.sleep(studyMin  * 60)
    playsound('repetition.wav')
    print('Take a break!')
    time.sleep(breakMin  * 60)

playsound('finish.wav')
print('Peace out, girl scout!')

The error:

Traceback (most recent call last):
  File "/usr/lib/python3.8/idlelib/run.py", line 559, in runcode
    exec(code, self.locals)
  File "/home/tstew/pypj/StudyTimer/pomodoro.py", line 13, in <module>
    playsound('repetition.wav')
TypeError: 'module' object is not callable

What I've done to try and fix this:
To preface this, I'm a beginner. I've tried to make sure all my python stuff is updated. Made sure to install the playsound module on both Python3 and Python. Originally I had the sounds stored in their own folder, now I've moved them to the root folder in hopes of it working.

Relevant information:
OS - Linux Mint
Python version - 3.8.10
Shell - Idle

CodePudding user response:

This is the correct import:

from playsound import playsound
  • Related