Python程序在可执行文件中不工作-存档,sqlite3,tkinter
我刚刚完成了我的第一个Python程序,它基本上归档了用户指定的文件。有一个用tkinter和sqlite3制作的GUI。最后,我让它在Python中运行良好。然后,我使用pyinstaller将其制作成一个.exe文件,而关键组件(归档)根本没有发生 在Archive()函数中,我创建了弹出窗口来显示路径,它们看起来都很好,因此线程正在工作,但实际的存档没有发生。下面是代码的一小部分,我认为这就是错误所在Python程序在可执行文件中不工作-存档,sqlite3,tkinter,python,sqlite,exe,executable,archiving,Python,Sqlite,Exe,Executable,Archiving,我刚刚完成了我的第一个Python程序,它基本上归档了用户指定的文件。有一个用tkinter和sqlite3制作的GUI。最后,我让它在Python中运行良好。然后,我使用pyinstaller将其制作成一个.exe文件,而关键组件(归档)根本没有发生 在Archive()函数中,我创建了弹出窗口来显示路径,它们看起来都很好,因此线程正在工作,但实际的存档没有发生。下面是代码的一小部分,我认为这就是错误所在 def Archiver(input_file, output_dir, 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是否会有所不同?是的,基本上可执行文件会被提取到一个临时目录,然后在那里运行。该目录的路径保存在名为
\u MEIPASS
的系统变量中。您可以查看如何检索该路径,并使用临时文件夹位置创建绝对路径