代码之家  ›  专栏  ›  技术社区  ›  Joyson

可执行文件上的python文件提取器

  •  0
  • Joyson  · 技术社区  · 6 年前

    我用python pyinstaller构建了一个可执行文件,需要 当我执行它拥有的文件时,在可执行文件中保留一些文件 将其他文件解压缩到特定路径,如安装 特定文件夹中的包。

    我已经做了以下工作

      pyinstaller -F --add-data 'installation.zip:installation.zip' --onefile
    

    但我不知道如何将可执行文件中的zip文件解压到 目的地。

    1 回复  |  直到 6 年前
        1
  •  0
  •   Joyson    6 年前

    我创造了 exe 使用以下代码

    pyinstaller -F --add-data "installation.zip;installation" phpfilescopy_extract.py --console --onefile
    

    我已经用下面的代码解压了zip文件。 Sys.yMeiPase-给出了我以前使用的临时EXE提取路径 找到zip文件并从路径中提取

    def excute(self):
    
        global src
        #source = src
        dst = 'd:/destination'
        # sys._MEIPASS - gives the temporary exe extraction path that i used to locate the zip files and extracted from the path
        source = sys._MEIPASS + "/installation/installation.zip"
    
    
        if os.path.exists(dst):
            if source.endswith('.zip'):
                file_zip = zipfile.ZipFile(source)
                file_zip.extractall(dst)
                QMessageBox.about(self, "Title", "all file's extracted")
            else:
                QMessageBox.about(self, "Title", "failed extract file")
        else:
            QMessageBox.about(self, "Title", "path not vialed ")