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
).

- 18,379
- 16
- 47
- 61

- 9
- 1
- 1
- 2
-
2Do you see the module if you type pip list in command line? – Stef van der Zon Dec 19 '18 at 13:11
-
This can also happen if the user running the script is different than the one that ran pip install. – Jared Smith Dec 19 '18 at 13:22
-
Also might happen if you're running Anaconda. In that case it's always better to instal through `conda` – Juan C Dec 19 '18 at 13:25
-
is it possible you installed it for different python installation e.g. python2 and trying to run script with python3? I think both are available – buran Dec 19 '18 at 13:25
-
1@vanderZonStef Yes, I can see the playsound version 1.2.2 – Aggeliki Kyr Dec 19 '18 at 14:00
-
@JaredSmith No, I have run both commands from the same user! – Aggeliki Kyr Dec 19 '18 at 14:03
-
@JuanC I am not running Anaconda. – Aggeliki Kyr Dec 19 '18 at 14:05
-
@AggelikiKyr fire up your python interpreter and try to import it directly – Jared Smith Dec 19 '18 at 14:07
-
@buran No, I just checked it. They are the exact same! Version 2.7.13 – Aggeliki Kyr Dec 19 '18 at 14:10
-
@JaredSmith Sorry, I am a beginner... How could I import it directly? – Aggeliki Kyr Dec 19 '18 at 14:14
-
@AggelikiKyr type 'python' without the quotes at a command prompt to get the python prompt, then type 'import playsound' (again without quotes). – Jared Smith Dec 19 '18 at 14:16
-
are you using a virtual environment? – Juan C Dec 19 '18 at 18:41
-
No, I am not using virtual environment! Eventually I deleted and reinstalled python version 3.5 and the problem was solved...I have no idea what I was doing wrong! Thanks for the support :) – Aggeliki Kyr Dec 20 '18 at 15:50
8 Answers
Just change from playsound import playsound
to import playsound

- 1,376
- 5
- 28
- 49

- 31
- 2
-
1Please format your code. This is done by enclosing the code part using `` – shuberman Oct 06 '19 at 17:51
The best solution that worked for me is uninstalling playsound using pip uninstall playsound and then installing it again using pip install playsound.

- 11
- 2
FOR UBUNTU 20.0 USERs
apt install python3
pip install playsound
myfile.py
from playsound import playsound
playsound('/path/to/a/sound/file/you/want/to/play.mp3')
// DO NOT USE CodeRunner coz it will use python2 by default (or in most of the case)
python3 myfile.py
(hit enter to run)

- 21
- 2
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.
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.

- 3
- 2
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

- 3,763
- 2
- 21
- 34

- 1
- 1
If you already installed the module and error still occurs then it can be problem of multiple python versions installed on your system try to uninstall all python versions and reinstall the latest python setup from official source.

- 1
i was facing the same problem try this: go to this path C:\Users\the_user_name\AppData\Local\Programs\Python\Python310\Lib\site-packages you will find the module here, cut it and paste to the lib directory
-
1Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 04 '23 at 11:12