关注服务器架构设计
关注互联网

Compile python to exe

When we write a python file, we can use command line “python test.py” 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:

 

1. py2exe

project link: http://sourceforge.net/projects/py2exe/

latest version just support python 2.6

Install py2exe

Create a python file named setup.py, code is:

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

 

2.python.cx_freeze

project link: http://sourceforge.net/projects/cx-freeze/

support python version 2.x 3.x

install it

Create a python file named setup.py, code is:

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("test.py", base="Win32GUI" icon = "test.ico")])

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

 

Then you can publish your application for user.

评论 6

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #3

    怎么感觉最近你的站访问响应都要等待一段时间的呀。

    话唠 Chrome浏览器 Windows 8.1 x64 Edition
    酷特尔3年前 (2014-07-14)回复
    • 貌似不稳定,有时快有时慢,可能跟google广告有关系

      神话 Chrome浏览器 Windows 7 x64 Edition
      eliteYang3年前 (2014-07-14)回复
  2. #2

    我去,画风不对啊..打算改发英文博客了啊
    – Here is two methods to make it.
    + Here are two methods to make it.
    我最常做的…

    神话 Chrome浏览器 Mac OS X
    Yu3年前 (2014-07-11)回复
    • 练练手,免得哪天朋友国际友人不会说话了

      神话 Chrome浏览器 Windows 7 x64 Edition
      eliteYang3年前 (2014-07-12)回复
  3. #1

    我一般用py2exe,不过这么搞确实不太值得,都是辅助测试,还不如直接安装环境呢

    畅言 Chrome浏览器 Windows 8.1 x64 Edition
    rangerlee3年前 (2014-07-11)回复
    • py2exe不支持3.x,所以没法用,主要是要给策划用,不能让人装Python啊

      神话 Chrome浏览器 Windows 7 x64 Edition
      eliteYang3年前 (2014-07-11)回复

ArkGameFrame游戏服务器解决方案

Github地址