cx_freeze可执行文件在构建后无法使用playound

时间:2017-12-03 21:50:19

标签: python cx-freeze playsound

使用playsound模块的简单工作代码在运行cx_freeze生成的exe时发出以下错误,而实际的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的{​​{1}}文件如下所示:

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]
      )
  • python versoin 2.7.13
  • 操作系统:Ubuntu 17:04 64位
  • cx_freeze version 5.1
  • playsound版本1.2.2

1 个答案:

答案 0 :(得分:0)

我终于解决了它。我在"gi"中向packages添加了setup.py。不明白为什么我必须添加这个额外的包,但为我工作。