在Python 3.6下使用cx_freeze创建可执行文件时,从PyQt5中排除不需要的.dll导入

时间:2017-08-31 16:12:15

标签: pyqt5 cx-freeze python-3.6

我有一个关于PyQt5和cx_freeze的问题,我希望你能帮助我。 我想知道是否有办法在使用cx_freeze创建可执行文件时从PyQt5库中排除不需要的.dll导入。这个请求来自这样一个事实:当我用cx_freeze创建我的可执行文件时,整个PyQt5库被导入,导致一个非常繁重的应用程序(~220 Mb)。

在我的cx_freeze setup.py中,我编写了以下代码:

import sys
from setuptools import setup, find_packages
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need
# fine tuning.

base = 'Win32GUI' if sys.platform=='win32' else None

build_options={ "packages": ["os", "numpy.core._methods", 
"numpy.lib.format", "pywinusb", "numpy"],
            "includes":["PyQt5.QtQml", "PyQt5.QtWidgets"],
            "excludes":["tkinter",
                        "PyQt5.QtBluetooth",
                        "PyQt5.QtNetwork",
                        "PyQt5.QtNfc",
                        "PyQt5.QtWebChannel",
                        "PyQt5.QtWebEngine",
                        "PyQt5.QtWebEngineCore",
                        "PyQt5.QtWebEngineWidgets",
                        "PyQt5.QtWebKit",
                        "PyQt5.QtWebKitWidgets",
                        "PyQt5.QtWebSockets",
                        "PyQt5.QtSql",
                        "PyQt5.QtNetwork",
                        "PyQt5.QtScript",
                        "numpy.core._dotblas"],
            "optimize": 2}

executables = [
    Executable('my_python_app.py', base=base)
] 

setup(
    name='my_python_app',
    version = '0.1',
    description = 'my_python_app',
    options = {"build_exe": build_options},
    executables = executables,
    platforms='windows',
    include_package_data = True,
    install_requires=None,
    namespace_packages=None,
    keywords = []
)

排除单个模块(例如“PyQt5.QtWebEngineCore”),不会自动排除关联的.dll库(大约40 Mb)。创建构建后,C:.. \ build \ exe.win32-3.6 \ PyQt5 \ Qt \ bin \ Qt5WebEngineCore.dll中存在.dll库。

由于某些库不需要,有没有办法告诉cx_freeze排除它们?

供参考,我正在使用:

  • Windows 7企业版,Service Pack 1
  • Python 3.6 32位
  • cx_Freeze-5.0.2

提前谢谢大家!

0 个答案:

没有答案