问题
I do have one question regarding PyQt5 and cx_freeze, and I hope you can help me. I would like to know if there is a way to exclude undesired .dll import from PyQt5 library while creating an executable with cx_freeze. This request comes from the fact that when I create my executable with cx_freeze the whole PyQt5 library is imported resulting in a quite heavy application (~220 Mb).
In my cx_freeze setup.py I have coded the following:
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 = []
)
Excluding the single modules (such as "PyQt5.QtWebEngineCore"), does not automatically exclude the associated .dll library (circa 40 Mb). After the build is created the .dll library in C:..\build\exe.win32-3.6\PyQt5\Qt\bin\Qt5WebEngineCore.dll is present.
As some of these libraries aren't needed, is there a way to tell cx_freeze to exclude them?
For reference, I'm using:
- Windows 7 Enterprise, Service Pack 1
- Python 3.6 32-bit
- cx_Freeze-5.0.2
Thank you all in advance!
来源:https://stackoverflow.com/questions/45985921/excluding-undesired-dll-import-from-pyqt5-while-creating-an-executable-with-cx