【发布时间】:2020-06-26 15:58:09
【问题描述】:
我刚刚完成了我的第一个 Python 程序,它基本上归档了用户指定的文件。有一个用 tkinter 和 sqlite3 制作的 GUI。最后我让它在 Python 中正常工作。然后我用 pyinstaller 把它变成了一个 .exe 文件,关键组件(归档)就没有发生。
在 Archive() 函数中,我创建了弹出窗口来显示路径,它们看起来都很好,所以线程正在工作,但实际存档没有发生。这是代码的一小部分,我认为是错误所在。
def Archiver(input_file, output_dir, archive_int):
while True:
global sched_var
time.sleep(archive_int*60)
input_name = os.path.basename(input_file)
main_dir = os.path.dirname(input_file)
if not os.path.exists(main_dir + '/temp'):
os.mkdir(main_dir + '/temp')
## copy file to temporary directory
shutil.copy(input_file, os.path.join(main_dir, 'temp'))
## hold all the paths in variables to check they are okay
tempfiledir = os.path.join(main_dir + '/temp/' + input_name)
archfile = input_file + "_" + time.strftime("%H%M_%d%m%Y")+'.rar'
outputarch = output_dir + '/' + input_name + "_" + time.strftime("%H%M_%d%m%Y")+'.rar'
messagebox.showinfo(title = 'tempfiledir', message = tempfiledir) ## all these seem okay
messagebox.showinfo(title = 'archfile', message = archfile)
messagebox.showinfo(title = 'outputarch', message = outputarch)
patoolib.create_archive(archfile,(tempfiledir,),) ## from here - nothing executed
messagebox.showinfo(title = 'Archive', message = 'Archive created')
shutil.move(archfile, outputarch)
messagebox.showinfo(title = 'Moved', message = 'Archive moved')
if sched_var == False:
break
正如我所说,它在 Python 中运行时运行良好,一旦文件是 .exe 文件,os.path 是否有不同之处?
【问题讨论】:
标签: python sqlite exe executable archiving