【问题标题】:Python programme not working in executable file - archiving,sqlite3, tkinterPython 程序在可执行文件中不起作用 - 归档、sqlite3、tkinter
【发布时间】: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


    【解决方案1】:

    是的,基本上可执行文件被提取到一个临时目录,然后在那里运行。该目录的路径保存在名为_MEIPASS 的系统变量中。您可以查看 here 以了解如何检索该路径并使用临时文件夹位置创建绝对路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-12
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多