简体   繁体   English

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

[英]Python files extractor on executable

I have build one executable file with python pyinstaller and need to keep some files within the executable when i execute the file it has to extract the other files to the specific path like installing a packages in specific folders. 我已经使用python pyinstaller构建了一个可执行文件,当我执行该文件时,需要将一些文件保留在可执行文件中,该文件必须将其他文件提取到特定路径,例如在特定文件夹中安装软件包。

i have done the following 我做了以下

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

but i don't have any idea how to extract the zip file in executable to the destination. 但我不知道如何将可执行文件中的zip文件提取到目标位置。

I have created the exe using this following code 我使用以下代码创建了exe文件

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

I have done extracting the zip file using this following code. 我已经使用以下代码提取了zip文件。 sys._MEIPASS - gives the temporary exe extraction path that i used to locate the zip files and extracted from the path sys._MEIPASS-给出我用来定位zip文件并从该路径提取的临时exe提取路径

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 ")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM