Cx_freeze排除不需要的库

时间:2017-08-18 00:43:43

标签: python python-3.x cx-freeze

我试图在我的构建中删除一些我不需要的库,但即使添加到列表中,它们仍会显示在构建日志中。

这是我的构建代码。

from cx_Freeze import setup, Executable

build_exe_options = {"excludes": ["tkinter", "PIL"], "include_files": 
['bin'], "optimize": 2}

setup(
    author="secret",
    name="app",
    options={"build_exe": build_exe_options},
    version="1.0",
    description="something",
    executables=[Executable("app.py", base="Console")])

我缺少什么?

1 个答案:

答案 0 :(得分:0)

您的代码看起来应该可以工作...您是否检查过命令行中是否正确引用了setup.py? 要排除你不需要的库,这就是我使用的:

import sys
from cx_Freeze import setup, Executable
import os    

build_exe_options = {"packages": ["os",                                  
                                  'numpy'
                                  ],
                     "excludes": ["PyQt4",
                                  "PyQt5",
                                  'matplotlib',                                  
                                  ],
                     "includes":["pandas",
                                 ],                     
                     "include_files": [r'C:\ProgramData\Anaconda3\DLLs\tcl86t.dll',
                                       r'C:\ProgramData\Anaconda3\DLLs\tk86t.dll',],
                     "optimize": 2,
                     }


base = None
if sys.platform == "win32":
    base = "Win32GUI"

name = "yourscript.py"

setup(  name = name,
        version = "0.1",
        description = "My GUI application!",
        options = {"build_exe": build_exe_options},
        executables = [Executable(name, base=base)])

这成功地排除了我不使用的大包,所以你可以尝试修改它。