How to package a Python program into an exe program using py2exe in Windows

Source: Internet
Author: User
This article mainly introduces how to package a Python program into an exe program using py2exe in Windows. This article mainly describes Python3.x, for more information, see py2exe. download from sourceforge only supports 2.7.

For versions of python3.0 +, you need to compile it yourself.
1. download source code

Svn checkout svn: // svn.code.sf.net/p/py2exe/svn/trunk py2exe-svn
2. Compiling Environment

Vs2014.
3. install

Entering py2exe-3

python setup.py install

Compilation and installation will be performed here.

In addition, python uses vs9 by default. for vs2014, you need to change the file:

The code is as follows:

Lib \ distutils \ msvc9compiler. py

Search:

The code is as follows:

VERSION = get_build_version ()

Add the following content:

The code is as follows:

VERSION = 11.0

If an error occurs:

The code is as follows:

Failed to load and parse the manifest. The system cannot find the file specified.

Error: command 'mt.exe 'failed with exit status 31

Solution: The link.exeafter vs2010is slightly changed. in this case, the manifestfile is not generated during the link, and mt.exe cannot find the file. Search for MANIFESTFILE in msvc9compiler. py and add a line of ld_args.append ('/MANIFEST') to it. (Python3.4 does not seem to have this problem. 2.7 exists)
4. setup. py

For details about setup. py, refer to the official website. The bundle-files parameter must be set to 0 if you want to compress the package.

Change can refer to: http://sourceforge.net/p/py2exe/svn/HEAD/tree/trunk/py2exe-3/
Add setup. py.

from distutils.core import setupimport py2exeimport sys,os if sys.version_info.major >= 3.0:  opt_bundle_files = 0else:  opt_bundle_files = 1includes = ["PyQt4.QtCore","PyQt4.QtGui","sip"]options = {"py2exe":     { "compressed": 1,      "optimize": 2,      "includes": includes,      "bundle_files": opt_bundle_files,     }   }setup(  version = "0.1.0",  description = "test_add",  options = options,  zipfile=None,  console=[{"script": "test_add.py", "icon_resources": [(1, "py.ico")] }],  #windows=[{"script": "test_add.py", "icon_resources": [(1, "py.ico")] }],)

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.