Python Packaging Tools Cx_freeze problem records and solutions

Source: Internet
Author: User

On the last day before the festival, all the problems encountered during the packaging process are resolved and can be successfully run! Really a good jackpot, hope that the new year all goes well!

The following are the problems and solutions that are encountered during the use of Cx_freeze (Win7)

    1. Problem Description: Run EXE, start countless main programs, causing the system to be unusable

cause : A multiprocessing package was used in the program

workaround : In the main file if __name__ = = "__main__": After adding Multiprocessing.freeze_support (), be sure to add at the beginning of the

2. Problem Description: After running, prompt in Freeze_support Sys.stdout.flush exception

            

    cause : Use of PYQT as interface, no console

    workaround : Before calling Multiprocessing.freeze_support (), redirect stdout and stderr, add: sys.stdout = io. Stringio () and sys.stderr = io. Stringio ()

3. Using the shelve module, debugging under the IDE can be used normally, cannot be used after packaging

    cause : Shelve's Open function also loads other database management modules in the run, without knowing what additional packages are needed, so that some of the necessary modules are missing when packaging

    Workaround : Modify the packaging script to add the following:

packages = []
For dbmodule in [' Dbhash ', ' gdbm ', ' dbm ', ' dumbdbm ']:
Try
__import__ (Dbmodule)
Except Importerror:
Pass
Else
# If We found the module, ensure it ' s copied to the build directory.
Packages.append (Dbmodule)

Options = {
' Build_exe ': {
' Includes ': ' Atexit ',
"Packages": Packages
}

}

4. Using Inspect.getsourcelines exception oserror:could not get source code

  cause : After packaging, all are PYC files, no source code, resulting in dynamic fetch code failure

  Workaround: Package The py file containing the required source code into the Library.zip file, and in the ' Build_exe ' parameter, add ' zip_includes ': [' path\\source.py ']

  

Python Packaging Tools Cx_freeze problem records and solutions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.