Compile PyQt4 Program (numpy & scipy) and cx_freezepyqt4 Based on cx_freeze
After developing the PyQt4 program, you need to provide it to others. The best way to do this is to compile the Python program into an exe file.
Usually I use cx_freeze to complete this job, that is, compile the setup. py file and execute python setup. py build.
(1) For General PyQt4 programs, the content of setup. py is as follows:
1 import sys 2 3 from cx_Freeze import setup, Executable 4 5 base = None 6 if sys. platform = 'win32 ': 7 base = 'win32gu' 8 9 options = {10 'build _ exe': {11 'regions': ['ateg'], 12 'cludes ': ['tkinter', 13 'collections. sys ', 14' collections. _ weakref '] 15} 16} 17 18 setup (19 name = "program name", 20 version = "version", 21 description = "", 22 options = options, 23 executables = [Executable ("Master absolute path", base = base, 24 icon = "icon absolute path")])
(2) After numpy is used, set setup. py:
1 import sys 2 3 from cx_Freeze import setup, Executable 4 5 base = None 6 if sys. platform = 'win32 ': 7 base = 'win32gu' 8 9 options = {10 'build _ exe': {11 'regions': ['ateg ', 12 'numpy'], 13 'cludes ': ['tkinter', 14' collections. sys ', 15' collections. _ weakref '] 16} 17} 18 19 setup (20 name = "program name", 21 version = "version number", 22 description = "", 23 options = options, 24 executables = [Executable ("Master absolute path", base = base, 25 icon = "icon absolute path")])
(3) When scipy is used, Import Error: No module named 'scipy' will appear during compilation using cx_freeze '.
In this case, the hooks under the cx_Freeze folder is required. py's 548th-line code "finder. includePackage ("scipy. lib ")" to "finder. includePackage ("scipy. _ lib ")".
Modify the corresponding setup. py as follows:
1 import sys 2 import numpy # Yes, otherwise _ ufuncs error 3 4 from cx_Freeze import setup, Executable 5 6 base = None 7 if sys. platform = 'win32 ': 8 base = 'win32gu' 9 10 options = {11 'build _ exe': {12 'packages ': ['scipy'], # Important 13 'uploads': ['ateg', 14 'numpy', 15 'scipy'], 16 'cludes ': ['tkinter', 17' collections. sys ', 18' collections. _ weakref '] 19} 20} 21 22 setup (23 name = "program name", 24 version = "version number", 25 description = "", 26 options = options, 27 executables = [Executable ("Master absolute path", base = base, 28 icon = "icon absolute path")])