简体   繁体   English

Pyinstaller-从最终可执行文件中排除文件

[英]Pyinstaller - Exclude files from final executable

I am developing an cross platform application which ships additional binary files from source directory for linux and windows. 我正在开发一个跨平台应用程序,该应用程序从Linux和Windows的源目录中附带了其他二进制文件。 Right now I am using following script in my *.spec file to include all binaries from the source directory. 现在,我正在* .spec文件中使用以下脚本来包含源目录中的所有二进制文件。

##### 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')

All works well. 一切正常。 Now the issue is that when i create binay from windows, all additional binaries of linux also shiped in the final executable. 现在的问题是,当我从Windows创建Binay时,Linux的所有其他二进制文件也都包含在最终的可执行文件中。 This makes the final stand alone executable bigger in size. 这使得最终的独立可执行文件更大。

Is there a way to tell pyinstaller to execlude certain files/ binarries from source directory. 有没有办法告诉pyinstaller从源目录执行某些文件/二进制文件。 Also is it possible to execlude certain *.so/ *.dll which are really not required in the final executable? 可以执行某些* .so / * .dll,而这些文件在最终可执行文件中实际上并不需要吗?

I use the following for development:- 我将以下内容用于开发:

Python 2.7 Python 2.7

Pyinstaller 2.1 Pyinstaller 2.1

Debian 7 for linux 适用于Linux的Debian 7

Windows 7 for Win Windows 7 Win版

Any help is appriciated. 任何帮助都适用。

sure just add a list of files to exclude 确保只添加要排除的文件列表

def extra_datas(mydir,exclude=[]):
    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)
    return [(f, f, 'DATA') for f om files if f not in exclude]

a.datas += extra_datas(some_dir,["something.txt","something.exe",...])

as for DLL's im pretty sure there is an explicit exlude to exclude dll's that would normally automagically be included 至于DLL,我很确定有一个明确的排除项来排除通常自动包含的DLL

[edit] see this answer wrt excluding dll's https://stackoverflow.com/a/17595149/541038 [edit]看到此答案wrt,不包括dll的https://stackoverflow.com/a/17595149/541038

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

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