0

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

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Aggeliki Kyr
  • 9
  • 1
  • 1
  • 2

8 Answers8

3

Just change from playsound import playsound to import playsound

Marten
  • 1,376
  • 5
  • 28
  • 49
1

The best solution that worked for me is uninstalling playsound using pip uninstall playsound and then installing it again using pip install playsound.

1

FOR UBUNTU 20.0 USERs

  1. apt install python3
  2. 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)

0

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.

0

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.

Seti
  • 3
  • 2
0

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

aaossa
  • 3,763
  • 2
  • 21
  • 34
0

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.

SANJ
  • 1
-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

  • 1
    Your 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