0

A simple working code with playsound module is giving following errors when I run the exe generated by cx_freeze while actual Python code runs without any errors.

waqas@waqas-pc:~/sound$ ./build/exe.linux-x86_64-2.7/sound.py 
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/cx_Freeze/initscripts/__startup__.py", line 14, in run
    module.run()
  File "/usr/local/lib/python2.7/dist-packages/cx_Freeze/initscripts/Console.py", line 26, in run
    exec(code, m.__dict__)
  File "sound.py", line 20, in <module>
    play_tune(tune)
  File "sound.py", line 14, in play_tune
    playsound.playsound(tune,True)
  File "/usr/local/lib/python2.7/dist-packages/playsound.py", line 91, in _playsoundNix
    import gi
  File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 42, in <module>
    from . import _gi
ImportError: No module named _error

How can I get this issue fixed?

My setup.py file for cx_freeze looks like below:

import sys
from cx_Freeze import setup, Executable

packages  = ["playsound", "os", "time", "multiprocessing"]    
Sound = Executable(
    script = "sound.py",
    targetName = "sound.py",
    )    
setup(name = "sound" ,
      version = "0.1" ,
      options = {"build_exe": {"packages": packages}},
      description = "" ,
      executables = [Sound]
      )

This is the code snippet I am trying to run:

#!/usr/bin/env python

import playsound
import os, time

def get_tune(tune_dir, tune_ext):
    for file in os.listdir(tune_dir):
        if file.endswith(tune_ext):
           return os.path.join(tune_dir, file)

def play_tune(tune):
    playsound.playsound(tune,True)

if __name__ == '__main__':
    tune = get_tune("./tunes", "mp3")
    play_tune(tune)
    x = raw_input("\n\n\t\tPress Any key to exit")
  • python versoin 2.7.13
  • OS: Ubuntu 17:04 64 bit
  • cx_freeze version 5.1
  • playsound version 1.2.2
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Waqas
  • 615
  • 1
  • 8
  • 20

1 Answers1

0

I finally solved it. I added "gi" to packages in my setup.py. Didn't understand why I had to add this additional package, but worked for me.

Waqas
  • 615
  • 1
  • 8
  • 20