'ImportError: no module named playsound
I am trying to run my Python code in raspberry Pi 3 and I keep getting the error: ImportError: no module named playsound. I have already successfully installed playsound (using the command: pip install playsound).
Solution 1:[1]
Just change from playsound import playsound to import playsound
Solution 2:[2]
The best solution that worked for me is uninstalling playsound using pip uninstall playsound and then installing it again using pip install playsound.
Solution 3:[3]
In my case, one module worked with pip3 install pygame but not playsound. I snooped through python files to see the difference between pygame and playsound. I found out that playsound was not in its folder: C:\Users\USER\AppData\Local\Programs\Python\Python39\Lib\site-packages.
So I moved it to C:\Users\USER\AppData\Local\Programs\Python\Python39\Lib\site-packages\playsound-1.2.2.dist-info
But remember to put it back after compiling it so you can use the module. Somehow it worked for me.
Solution 4:[4]
I have 100% found this solution in vs code or other IDE. You need to just change your python interpreter.
Firstly go to view tab in vs code and select command palette, then search python:Select interpreter, and then select system recommended path then open your vs code:
from playsound import playsound
playsound('C:\\\Users\\\UmAr\\\Desktop\\\smarterway python\\\book\\\cor\\\play.mp3')
Remember: use double backslash (\) in your mp3 file location because single backslash is a special meaning in python
Solution 5:[5]
The problem according to the best of my knowledge, it is the environment, by default the raspberry pi is running python2 on the command terminal, and I guess you are running your program on thonny idle or the python3 idle, so what you are doing is your are using python2 environment to install playsound(Terminal) and then using the python3 environment to run your program. So what I did is i used this command on the terminal sudo apt-get remove python2.7 --purge sudo apt-get install python3.5 pip3 install playsound and behold no module error.
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 | Marten |
| Solution 2 | |
| Solution 3 | |
| Solution 4 | aaossa |
| Solution 5 | Raymond Jude Druart |
