下面把hello.py转换成exe执行文件。
1、hello world 例子

1 print "Hello World!"
2 

下载:hello.py
2、配置文件(setup.py

1 from distutils.core import setup
2 import py2exe
3 
4 setup(console=['hello.py'])
5 

如果要转换其他的python文件,可以把其中的'hello.py‘你想要转换的文件的文件名。而且一定要把hello.py文件放到要转换的python程序
的相同目录下才可以。
3、执行《路径\python setup.py py2exe》
例如:
C:\Tutorial>python setup.py py2exe
running py2exe
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'zlib'
creating python loader for extension 'unicodedata'
creating python loader for extension 'bz2'
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
byte-compiling C:\Tutorial\build\bdist.win32\winexe\temp\bz2.py to bz2.pyc
byte-compiling C:\Tutorial\build\bdist.win32\winexe\temp\unicodedata.py to unicodedata.pyc
byte-compiling C:\Tutorial\build\bdist.win32\winexe\temp\zlib.py to zlib.pyc
skipping byte-compilation of c:\Python24\lib\StringIO.py to StringIO.pyc

[skipping many lines for brevity]

skipping byte-compilation of c:\Python24\lib\warnings.py to warnings.pyc
*** copy extensions ***
*** copy dlls ***
copying c:\Python24\lib\site-packages\py2exe\run.exe -> C:\Tutorial\dist\hello.exe

*** binary dependencies ***
Your executable(s) also depend on these dlls which are not included,
you may or may not need to distribute them.

Make sure you have the license if you distribute any of them, and
make sure you don't distribute files belonging to the operating system.

   ADVAPI32.dll - C:\WINDOWS\system32\ADVAPI32.dll
   USER32.dll - C:\WINDOWS\system32\USER32.dll
   SHELL32.dll - C:\WINDOWS\system32\SHELL32.dll
   KERNEL32.dll - C:\WINDOWS\system32\KERNEL32.dll

如果有以上的显示,那么表示成功了,在这个文件夹下便会多了2个文件夹build和dist,在dist中就会找到hello.exe执行文件。
posted on 2006-09-07 20:15  FireYang  阅读(876)  评论(0编辑  收藏  举报