Error Python PlaySound No module named 'gi'

9k Views Asked by At

when I request using "playsound" library for Python to play the audio file .mp3 it returns me the following error:

Code:

import playsound

playsound.playsound("test.mp3")

Error:

Traceback (most recent call last):
  File "/home/enzoportela/PycharmProjects/SoftwareRover2018.2/SoftRover/I.A Rover(2018.2).py", line 25, in <module>
    playsound.playsound("test.mp3")
  File "/home/enzoportela/anaconda3/envs/SoftwareRover2018.2/lib/python3.6      /site-packages/playsound.py", line 91, in _playsoundNix
    import gi
ModuleNotFoundError: No module named 'gi'
2

There are 2 best solutions below

0
On

It seems like you are using an anaconda environment. I also faced this issue and fixed it by doing the following:

First, create a symlink to gi module in your system Python. For me, the command is as follows:

ln -s /usr/lib/python3/dist-packages/gi/ /home/USERNAME/miniconda3/lib/python3.7/site-packages/

Then, open the directory:

cd /home/USERNAME/miniconda3/lib/python3.7/site-packages/gi/

and run the following commands:

sudo cp _gi.cpython-35m-x86_64-linux-gnu.so _gi.cpython-37m-x86_64-linux-gnu.so
sudo cp _gi_cairo.cpython-35m-x86_64-linux-gnu.so _gi_cairo.cpython-37m-x86_64-linux-gnu.so

My system Python is 3.5 and miniconda Python is 3.7. Your versions may differ from mine, so take care of that in the commands above (-35m- and -37m-).

Method obtained from askubuntu

0
On

The most simple way is the vext approach.

pip install vext
pip install vext.gi

Reference: How do I install python3-gi within virtualenv?