This article describes how to solve the problems and solutions of the Pythoncx_freeze packaging tool. For more information, see the following: problems encountered during the use of cx_freeze and solutions (Win7)
1. Problem description:Run exe and start countless main programs, making the system unusable
Cause: the multiprocessing package is used in the program.
Solution: after the main file if _ name _ = "_ main _":, add multiprocessing. freeze_support (). Be sure to add it at the beginning.
2. Problem description:After the command is run, the system. stdout. flush is abnormal in freeze_support.
Cause: the PyQT interface is used, and there is no console
Solution: Redirect stdout and stderr before calling multiprocessing. freeze_support () and add: sys. stdout = io. StringIO () and sys. stderr = io. StringIO ()
3. Use the shelve ModuleIDE debugging can be used normally and cannot be used after Packaging
Cause: the open function of shelve will be loaded into other database management modules during operation, so it does not know which additional packages are needed. Therefore, some necessary modules are missing during packaging.
Solution: Modify the packaging script and add the following content:
packages = []for dbmodule in ['dbhash', 'gdbm', 'dbm', 'dumbdbm']:try:__import__(dbmodule)except ImportError:passelse:# If we found the module, ensure it's copied to the build directory.packages.append(dbmodule)options = {'build_exe': {'includes': 'atexit',"packages": packages}}
4. An error occurred while using inspect. getsourcelines. OSError: cocould not get source code
Cause: After packaging, all the files are pyc files, and no source code exists, causing dynamic code acquisition failure.
Solution: pack the pyfile containing the required source code to the library.zip file. In the 'build _ exe 'parameter, add 'zip _ upload': ['path \ source. py']
I have shared with you the ideas and solutions of the Python cx_freeze packaging tool, and hope to help you.