I encoded a tiny python program using PyQt4. Now I want to use cx_Freeze to create a standalone application. Everything works fine - cx_Freeze automatically includes all the necessary modules; Received exe works.
The only problem is that cx_Freeze contains many unnecessary modules offline. Although I use only QtCore and QtGui, modules such as sqlite3, QtNetwork, or QtScript are also included. Surprisingly, in the resulting folder, I also found the PyQt5 DLL. It seems to me that cx_Freeze uses all the PyQt packages that I installed. The result is a 200 MB program - although I wrote only a small script.
How can I prevent this behavior?
I use the following setup.py:
import sys from cx_Freeze import setup, Executable setup( name="MyProgram", version="0.1", description="MyDescription", executables=[Executable("MyProgram.py", base = "Win32GUI")], )
I tried to explicitly exclude some packages (although rather randomly exclude all unused Qt modules) by adding this code:
build_exe_options = {"excludes": ["tkinter", "PyQt4.sqlite3", "PyQt4.QtOpenGL4", "PyQt4.QtSql"]}
but the top modules were still in use. I also tried
build_exe_options = {"excludes": ["tkinter", "PyQt4.sqlite3", "QtOpenGL4", "QtSql"]}
with the same result.
In addition to the incomplete Qt packages, I also find unbuilt folders with names such as "imageformats", "tcl", and "tk". How can I include only the necessary files in order to leave the offline folder and the installer as little as possible?
I searched for this problem for hours, but found this thread that didn't help me.
I am running python 3.4.2 amd64 on Windows 8.
I am happy with every decision that gives me the desired result, "autonomous" with a reasonable size. I also tried pyqtdeploy, but ran into an error: Unknown module in QT (but this is another question).
Edit:
I use two modules. One of them is a GUI class created by uic, "MyProgramGUIPreset". This file has the following import commands:
from PyQt4 import QtCore, QtGui from matplotlibwidget import MatplotlibWidget
In the main module, I do the following imports:
import MyProgramGUIPreset import numpy as np from PyQt4.QtGui import QApplication, QMainWindow, QMessageBox import sys from math import *
Perhaps this helps to find out what the problem is.