Python cx_freeze packaging tool to solve the problem ideas and solutions, pythoncx_freeze

Source: Internet
Author: User

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

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.