Including a directory using Pyinstaller

前端 未结 5 930
轻奢々
轻奢々 2020-12-01 05:43

All of the documentation for Pyinstaller talks about including individual files. Is it possible to include a directory, or should I write a function to create the include ar

5条回答
  •  甜味超标
    2020-12-01 06:18

    Paste the following after a = Analysis() in the spec file to traverse a directory recursively and add all the files in it to the distribution.

    ##### include mydir in distribution #######
    def extra_datas(mydir):
        def rec_glob(p, files):
            import os
            import glob
            for d in glob.glob(p):
                if os.path.isfile(d):
                    files.append(d)
                rec_glob("%s/*" % d, files)
        files = []
        rec_glob("%s/*" % mydir, files)
        extra_datas = []
        for f in files:
            extra_datas.append((f, f, 'DATA'))
    
        return extra_datas
    ###########################################
    
    # append the 'data' dir
    a.datas += extra_datas('data')
    

提交回复
热议问题