Error Python PlaySound No module named 'gi'
Asked Answered
L

2

12

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'
Lair answered 18/11, 2018 at 20:37 Comment(0)
B
2

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

Barnardo answered 22/11, 2018 at 0:12 Comment(0)
P
2

The most simple way is the vext approach.

pip install vext
pip install vext.gi

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

Pleiad answered 15/11, 2020 at 16:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.