py2exe,生成可执行文件.

py2exe,用python脚本生成可执行文件
Py2exe 官网:
http://www.py2exe.org/

先要写一个setup的脚本,格式如下:

#!/usr/bin/env python

from distutils.core import setup

setup(name=’Distutils’,
      version=’1.0′,
      description=’Python Distribution Utilities’,
      author=’Greg Ward’,
      author_email=’gward@python.net‘,
      url=’http://www.python.org/sigs/distutils-sig/’,
      packages=['distutils', 'distutils.command'],
     )
假设你准备转换的脚本保存为myscript.py 

然后写setup.py,内容如下:

# setup.py
from distutils.core import setup
import py2exe

setup(console=["myscript.py"])
如果你想要在你的py程序运行时候不在别后显示讨厌的shell黑框,你只要把console=["myscript.py"] 替换成windows=["myscript.py"].

然后在shell当中运行如下内容:

python setup.py py2exe
OK,exe程序轻松搞定。

来点复杂的:
如果你想把你的py程序注册成为windows nt的服务程序。只要把脚本修改成如下就可以了:

# setup.py
from distutils.core import setup
import py2exe

setup(service=["MyService"]) http://hi.baidu.com/webtalk/blog/item/2f0d0708f01572d163d9863c.html

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

No related posts.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Contact us

Admin: Bryan Wu