我已经弄清楚它是如何在没有导入模块的单个脚本上运行的。这是一个问题,因为我之前编写了一个类似于闹钟的脚本,但是为了播放所选的wav文件(输入是文件名),我需要一个名为simpleaudio的第三方模块。
如何让exe正确运行脚本?
alarm.py:
import simpleaudio
import subprocess
import datetime
print("Set a wav audio file")
wav = input()
wav = str(wav)
print("Set alarm time")
print("hour.minute")
alarmtime = input()
alarmtime = str(alarmtime)
while alarmtime != "%02d.%02d" % (datetime.datetime.now().time().hour, datetime.datetime.now().time().minute):
print("%02d.%02d.%02d" % (datetime.datetime.now().time().hour, datetime.datetime.now().time().minute, datetime.datetime.now().time().second))
print("Playing",wav)
wave_obj = simpleaudio.WaveObject.from_wave_file(wav)
play_obj = wave_obj.play()
play_obj.wait_done()
setup.py:
import cx_Freeze
import sys
import simpleaudio
import subprocess
import datetime
executables = [cx_Freeze.Executable("alarm.py")]
cx_Freeze.setup(
name = "alarm",
options = {"build_exe": {"packages":["simpleaudio","subprocess","datetime"], "include_files":["rasputin.wav"]}},
executables = executables
)