Below Windows is a tutorial to package the Python program into the exe program using py2exe

  • 2020-05-07 19:56:56
  • OfStack

py2exe is only supported up to 2.7 in sourceforge downloads.

For python 3.0+, you need to compile it yourself.
1. Download the source

svn checkout svn:// py2exe-svn
2. Compile environment

vs2014 is used here.
3. Install

Enter the py2exe - 3

python install

There will be compilation and installation.

In addition, python USES vs9 by default. For vs2014, the following file needs to be changed:


Looking for:

VERSION = get_build_version()


VERSION = 11.0

If an error occurs:

Failed to load and parse the manifest. The system cannot find the file specified.
error: command 'mt.exe' failed with exit status 31

Solution: since the parameters of link.exe were slightly changed after vs2010, manifest file was not generated at link, and naturally mt.exe could not find this file. Just search MANIFESTFILE for 1 in, and then add a line ld_args.append ('/MANIFEST') to OK. (python 3.4 seems to have no such problem, while 2.7 exists) can refer to the official website, where the parameter -- bundle-files, which needs to be specifically mentioned, is set to 0 if you want to pack 1 package.

Changes can be reference: http: / / sourceforge net/p/py2exe/svn HEAD/tree/trunk/py2exe - 3 /
ends with

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

Related articles: