仅使用所需的库构建可执行文件?

时间:2019-08-02 15:37:05

标签: python executable cx-freeze

我正在使用cx_freeze构建独立的可执行文件。以下是此类setup.py文件的示例。

import os
import sys
from cx_Freeze import setup, Executable

base = None
if sys.platform == 'win32':
    base = 'Win32GUI'
exe = [Executable("main.py")]
os.environ['TCL_LIBRARY'] = r'C:\\Users\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\\Users\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tk8.6'
options = {
  'build_exe': {
    'includes': ['scipy.io', 'scipy.spatial.ckdtree'],
    'include_files': [r'C:\\Users\\dmurugesan\\AppData\\Local\\Programs\\Python\\Python36\\DLLs\\tcl86t.dll',
                      r'C:\\Users\\dmurugesan\\AppData\\Local\\Programs\\Python\\Python36\\DLLs\\tk86t.dll',
                      r'C:\\Users\\dmurugesan\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages\\'
                      r'pyqt5_tools\\platforms\\qwindows.dll'],
    'packages': ['pkg_resources._vendor', 'numpy', 'scipy', 'pydub', 'soundfile', 'cffi'],
  }
}

setup(name="lTBA", version="0.4", description='To be added',
  options=options, executables=exe)

尽管在提到要包含的库列表之后,构建中仍包含了环境中存在的所有库!我该如何克服?

1 个答案:

答案 0 :(得分:1)

您可以定义要排除的库:

'build_exe': {
    'excludes': ['library1_name', 'library2_name'], 
    # ...
}