Python cx_freeze packaging tool to solve the problem ideas and solutions, pythoncx_freeze
The following are the problems encountered during the use of cx_freeze and Their 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.
Articles you may be interested in:
- Package python with cx_freeze. exe example
- A simple method to package Python code into jar Software
- How to package a Python script file into an executable file
- How to package a Python program into an exe program using py2exe in Windows
- Python package with py2exe
- Compress python crawlers to generate exe files
- How to package and release Python code
- Python uses a memory zipfile object to package files in the memory. Example