0

playsound当我运行生成的 exe 时,带有模块的简单工作代码会出现以下错误,cx_freeze而实际 Python 代码运行时没有任何错误。

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

我怎样才能解决这个问题?

我的setup.py文件cx_freeze如下所示:

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

这是我试图运行的代码片段:

#!/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版本2.7.13
  • 操作系统:Ubuntu 17:04 64 位
  • cx_freeze 版本 5.1
  • 播放声音版本 1.2.2
4

1 回答 1

0

我终于解决了。我"gi"packages我的setup.py. 不明白为什么我必须添加这个额外的包,但对我有用。

于 2017-12-04T15:55:08.913 回答