'Beginner: Python sound modules not working (Circular Import)
After installation of playsound and simpleaudio modules to try simple commands in order to play some audio files I always get the following message.
playsound: ImportError: cannot import name 'playsound' from partially initialized module 'playsound' (most likely due to a circular import) (/Users/joaosoares/Documents/PySound/playsound.py)
simpleaudio:AttributeError: partially initialized module 'simpleaudio' has no attribute 'WaveObject' (most likely due to a circular import)
I am currently using python 3.8.1, I've tried to create a new environment using pipenv and the problem persists. I got it to work the very first time I installed playsound. The problem might came after I had to install AppKit.NSSound as needed to run simplesound. My problem may be obvious and I apologise in advance if my issue isn't clarified I started to use python very recently.
I am following this tutorial
Playsound file code:
from playsound import playsound
playsound('myfile.wav')
simpleaudio file:
import simpleaudio as sa
filename = 'myfile.wav'
wave_obj = sa.WaveObject.from_wave_file(filename)
play_obj = wave_obj.play()
play_obj.wait_done() # Wait until sound has finished playing
Solution 1:[1]
The only way i can reproduce your error is if i create a file called playsound.py
from playsound import playsound
playsound('myfile.wav')
ERROR
Traceback (most recent call last):
File "C:/Users/Chris/PycharmProjects/stackoverflow/stackoverflow.py", line 1, in <module>
from playsound import playsound
File "C:\Users\Chris\PycharmProjects\stackoverflow\playsound.py", line 1, in <module>
from playsound import playsound
ImportError: cannot import name 'playsound' from partially initialized module 'playsound' (most likely due to a circular import) (C:\Users\Chris\PycharmProjects\stackoverflow\playsound.py)
In your question your error specifically says your file is called playsound.py
/Users/joaosoares/Documents/PySound/playsound.py
rename this to something else otherwise it will try to import its self
Solution 2:[2]
There is Error in playsound Module So I has solved it for beginners Hope so it's useful for you
Write This Command in Terminal that is provided in the image https://i.stack.imgur.com/j6zcN.png And Then Again Run the Python File and the Error is Solved Now you can play sound using playsound module https://i.stack.imgur.com/VQiNN.png Note : Use double \ in path if you are a windows user else use \ in Mac and also enter Correct Path of song
Solution 3:[3]
just remove that playsound (use another name) and you are done
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Chris Doyle |
Solution 2 | |
Solution 3 | Mahaveer Janagouda |