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