Compile python to exe

作者: NickYang 分类: 技术文章,程序开发 发布时间: 2014-07-11 11:47

When we write a python file, we can use command line “python” to execute this file, but we need python environment, when publish programs, most user don’t have python in their PC, so sometimes we need to transfer python to executable file, like exe.


Here are two methods to make it.

Suppose our code like below:

if __name__ == "__main__":
    print("Hello world!")


1. py2exe

project link:

latest version just support python 2.6

Install py2exe

Create a python file named, code is:

from distutils.core import setup
import py2exe


then execute in command:
python py2exe
It will generate a dir named dist, dir dist include test.exe, python26.dll,, etc.



project link:

support python version 2.x 3.x

install it

Create a python file named, code is:

# encoding:utf-8
from cx_Freeze import setup, Executable
name = "test",
version = "0.1",
descrīption = "This is a test",
executables = [Executable("", icon = "test.ico")])

Now you can see, cx_freeze can set an icon for your exe, default it based console application, also you can set application based win32gui like this
executables = [Executable("", base="Win32GUI" icon = "test.ico")])

then execute in command
python build
build is a dir, it include some *.pyd, python26.dll,, test.exe, etc.


Then you can publish your application for user.


  • 酷特尔

    2014 年 7 月 14 日 06:18


    1. eliteYang

      2014 年 7 月 14 日 14:55


  • Yu

    2014 年 7 月 11 日 23:18

    – Here is two methods to make it.
    + Here are two methods to make it.

    1. eliteYang

      2014 年 7 月 12 日 14:54


  • rangerlee

    2014 年 7 月 11 日 17:29


    1. eliteYang

      2014 年 7 月 11 日 21:21



电子邮件地址不会被公开。 必填项已用*标注