设为首页 收藏本站
查看: 889|回复: 0

[经验分享] python py2exe 创建exe可执行文件

[复制链接]

尚未签到

发表于 2017-5-6 13:39:28 | 显示全部楼层 |阅读模式
python py2exe 创建exe可执行文件
2011年08月26日
  下载安装py2exehttp://sourceforge.net/projects/py2exe/files/py2exe/
  以上地址,可下载各个python相应版的py2exe版本.值得收藏!!
  安装后的文件应该在你的python安装目录下的Lib\site-packages\py2exe
  呵先来个简单的测试程序:
  Hello.py文件内容如下 :
  def main():
  print "Hello, World!"
  if __name__ == '__main__':
  main()
  然后为使用py2exe写一个脚本setup.py内容如下 :
  from distutils.core import setup
  import py2exe
  setup(console=["Hello.py"])
  运行setup.py,记得要传一个参数给它
  进入你程序所存放目录如:
  C:\Python26\hello\
  输入:setup.py py2exe
  *** finding dlls needed ***
  *** create binaries ***
  *** byte compile python files ***
  byte-compiling C:\Python26\hello\build\bdist.win32\winexe\temp\bz2.py to bz2.pyc
  byte-compiling C:\Python26\hello\build\bdist.win32\winexe\temp\select.py to sele
  ct.pyc
  byte-compiling C:\Python26\hello\build\bdist.win32\winexe\temp\unicodedata.py to
  unicodedata.pyc
  byte-compiling C:\Python26\lib\StringIO.py to StringIO.pyc
  byte-compiling C:\Python26\lib\UserDict.py to UserDict.pyc
  byte-compiling C:\Python26\lib\__future__.py to __future__.pyc
  byte-compiling C:\Python26\lib\_abcoll.py to _abcoll.pyc
  byte-compiling C:\Python26\lib\_strptime.py to _strptime.pyc
  byte-compiling C:\Python26\lib\_threading_local.py to _threading_local.pyc
  byte-compiling C:\Python26\lib\abc.py to abc.pyc
  byte-compiling C:\Python26\lib\atexit.py to atexit.pyc
  byte-compiling C:\Python26\lib\base64.py to base64.pyc
  byte-compiling C:\Python26\lib\bdb.py to bdb.pyc
  byte-compiling C:\Python26\lib\bisect.py to bisect.pyc
  byte-compiling C:\Python26\lib\calendar.py to calendar.pyc
  byte-compiling C:\Python26\lib\cmd.py to cmd.pyc
  byte-compiling C:\Python26\lib\codecs.py to codecs.pyc
  byte-compiling C:\Python26\lib\collections.py to collections.pyc
  byte-compiling C:\Python26\lib\copy.py to copy.pyc
  byte-compiling C:\Python26\lib\copy_reg.py to copy_reg.pyc
  byte-compiling C:\Python26\lib\difflib.py to difflib.pyc
  byte-compiling C:\Python26\lib\dis.py to dis.pyc
  byte-compiling C:\Python26\lib\doctest.py to doctest.pyc
  byte-compiling C:\Python26\lib\dummy_thread.py to dummy_thread.pyc
  byte-compiling C:\Python26\lib\encodings\__init__.py to encodings\__init__.pyc
  creating C:\Python26\hello\build\bdist.win32\winexe\collect-2.6\encodings
  byte-compiling C:\Python26\lib\encodings\aliases.py to encodings\aliases.pyc
  byte-compiling C:\Python26\lib\encodings\ascii.py to encodings\ascii.pyc
  byte-compiling C:\Python26\lib\encodings\base64_codec.py to encodings\base64_cod
  ec.pyc
  byte-compiling C:\Python26\lib\encodings\big5.py to encodings\big5.pyc
  byte-compiling C:\Python26\lib\encodings\big5hkscs.py to encodings\big5hkscs.pyc
  byte-compiling C:\Python26\lib\encodings\bz2_codec.py to encodings\bz2_codec.pyc
  byte-compiling C:\Python26\lib\encodings\charmap.py to encodings\charmap.pyc
  byte-compiling C:\Python26\lib\encodings\cp037.py to encodings\cp037.pyc
  byte-compiling C:\Python26\lib\encodings\cp1006.py to encodings\cp1006.pyc
  byte-compiling C:\Python26\lib\encodings\cp1026.py to encodings\cp1026.pyc
  byte-compiling C:\Python26\lib\encodings\cp1140.py to encodings\cp1140.pyc
  byte-compiling C:\Python26\lib\encodings\cp1250.py to encodings\cp1250.pyc
  byte-compiling C:\Python26\lib\encodings\cp1251.py to encodings\cp1251.pyc
  byte-compiling C:\Python26\lib\encodings\cp1252.py to encodings\cp1252.pyc
  byte-compiling C:\Python26\lib\encodings\cp1253.py to encodings\cp1253.pyc
  byte-compiling C:\Python26\lib\encodings\cp1254.py to encodings\cp1254.pyc
  byte-compiling C:\Python26\lib\encodings\cp1255.py to encodings\cp1255.pyc
  byte-compiling C:\Python26\lib\encodings\cp1256.py to encodings\cp1256.pyc
  byte-compiling C:\Python26\lib\encodings\cp1257.py to encodings\cp1257.pyc
  byte-compiling C:\Python26\lib\encodings\cp1258.py to encodings\cp1258.pyc
  byte-compiling C:\Python26\lib\encodings\cp424.py to encodings\cp424.pyc
  byte-compiling C:\Python26\lib\encodings\cp437.py to encodings\cp437.pyc
  byte-compiling C:\Python26\lib\encodings\cp500.py to encodings\cp500.pyc
  byte-compiling C:\Python26\lib\encodings\cp737.py to encodings\cp737.pyc
  byte-compiling C:\Python26\lib\encodings\cp775.py to encodings\cp775.pyc
  byte-compiling C:\Python26\lib\encodings\cp850.py to encodings\cp850.pyc
  byte-compiling C:\Python26\lib\encodings\cp852.py to encodings\cp852.pyc
  byte-compiling C:\Python26\lib\encodings\cp855.py to encodings\cp855.pyc
  byte-compiling C:\Python26\lib\encodings\cp856.py to encodings\cp856.pyc
  byte-compiling C:\Python26\lib\encodings\cp857.py to encodings\cp857.pyc
  byte-compiling C:\Python26\lib\encodings\cp860.py to encodings\cp860.pyc
  byte-compiling C:\Python26\lib\encodings\cp861.py to encodings\cp861.pyc
  byte-compiling C:\Python26\lib\encodings\cp862.py to encodings\cp862.pyc
  byte-compiling C:\Python26\lib\encodings\cp863.py to encodings\cp863.pyc
  byte-compiling C:\Python26\lib\encodings\cp864.py to encodings\cp864.pyc
  byte-compiling C:\Python26\lib\encodings\cp865.py to encodings\cp865.pyc
  byte-compiling C:\Python26\lib\encodings\cp866.py to encodings\cp866.pyc
  byte-compiling C:\Python26\lib\encodings\cp869.py to encodings\cp869.pyc
  byte-compiling C:\Python26\lib\encodings\cp874.py to encodings\cp874.pyc
  byte-compiling C:\Python26\lib\encodings\cp875.py to encodings\cp875.pyc
  byte-compiling C:\Python26\lib\encodings\cp932.py to encodings\cp932.pyc
  byte-compiling C:\Python26\lib\encodings\cp949.py to encodings\cp949.pyc
  byte-compiling C:\Python26\lib\encodings\cp950.py to encodings\cp950.pyc
  byte-compiling C:\Python26\lib\encodings\euc_jis_2004.py to encodings\euc_jis_20
  04.pyc
  byte-compiling C:\Python26\lib\encodings\euc_jisx0213.py to encodings\euc_jisx02
  13.pyc
  byte-compiling C:\Python26\lib\encodings\euc_jp.py to encodings\euc_jp.pyc
  byte-compiling C:\Python26\lib\encodings\euc_kr.py to encodings\euc_kr.pyc
  byte-compiling C:\Python26\lib\encodings\gb18030.py to encodings\gb18030.pyc
  byte-compiling C:\Python26\lib\encodings\gb2312.py to encodings\gb2312.pyc
  byte-compiling C:\Python26\lib\encodings\gbk.py to encodings\gbk.pyc
  byte-compiling C:\Python26\lib\encodings\hex_codec.py to encodings\hex_codec.pyc
  byte-compiling C:\Python26\lib\encodings\hp_roman8.py to encodings\hp_roman8.pyc
  byte-compiling C:\Python26\lib\encodings\hz.py to encodings\hz.pyc
  byte-compiling C:\Python26\lib\encodings\idna.py to encodings\idna.pyc
  byte-compiling C:\Python26\lib\encodings\iso2022_jp.py to encodings\iso2022_jp.p
  yc
  byte-compiling C:\Python26\lib\encodings\iso2022_jp_1.py to encodings\iso2022_jp
  _1.pyc
  byte-compiling C:\Python26\lib\encodings\iso2022_jp_2.py to encodings\iso2022_jp
  _2.pyc
  byte-compiling C:\Python26\lib\encodings\iso2022_jp_2004.py to encodings\iso2022
  _jp_2004.pyc
  byte-compiling C:\Python26\lib\encodings\iso2022_jp_3.py to encodings\iso2022_jp
  _3.pyc
  byte-compiling C:\Python26\lib\encodings\iso2022_jp_ext.py to encodings\iso2022_
  jp_ext.pyc
  byte-compiling C:\Python26\lib\encodings\iso2022_kr.py to encodings\iso2022_kr.p
  yc
  byte-compiling C:\Python26\lib\encodings\iso8859_1.py to encodings\iso8859_1.pyc
  byte-compiling C:\Python26\lib\encodings\iso8859_10.py to encodings\iso8859_10.p
  yc
  byte-compiling C:\Python26\lib\encodings\iso8859_11.py to encodings\iso8859_11.p
  yc
  byte-compiling C:\Python26\lib\encodings\iso8859_13.py to encodings\iso8859_13.p
  yc
  byte-compiling C:\Python26\lib\encodings\iso8859_14.py to encodings\iso8859_14.p
  yc
  byte-compiling C:\Python26\lib\encodings\iso8859_15.py to encodings\iso8859_15.p
  yc
  byte-compiling C:\Python26\lib\encodings\iso8859_16.py to encodings\iso8859_16.p
  yc
  byte-compiling C:\Python26\lib\encodings\iso8859_2.py to encodings\iso8859_2.pyc
  byte-compiling C:\Python26\lib\encodings\iso8859_3.py to encodings\iso8859_3.pyc
  byte-compiling C:\Python26\lib\encodings\iso8859_4.py to encodings\iso8859_4.pyc
  byte-compiling C:\Python26\lib\encodings\iso8859_5.py to encodings\iso8859_5.pyc
  byte-compiling C:\Python26\lib\encodings\iso8859_6.py to encodings\iso8859_6.pyc
  byte-compiling C:\Python26\lib\encodings\iso8859_7.py to encodings\iso8859_7.pyc
  byte-compiling C:\Python26\lib\encodings\iso8859_8.py to encodings\iso8859_8.pyc
  byte-compiling C:\Python26\lib\encodings\iso8859_9.py to encodings\iso8859_9.pyc
  byte-compiling C:\Python26\lib\encodings\johab.py to encodings\johab.pyc
  byte-compiling C:\Python26\lib\encodings\koi8_r.py to encodings\koi8_r.pyc
  byte-compiling C:\Python26\lib\encodings\koi8_u.py to encodings\koi8_u.pyc
  byte-compiling C:\Python26\lib\encodings\latin_1.py to encodings\latin_1.pyc
  byte-compiling C:\Python26\lib\encodings\mac_arabic.py to encodings\mac_arabic.p
  yc
  byte-compiling C:\Python26\lib\encodings\mac_centeuro.py to encodings\mac_centeu
  ro.pyc
  byte-compiling C:\Python26\lib\encodings\mac_croatian.py to encodings\mac_croati
  an.pyc
  byte-compiling C:\Python26\lib\encodings\mac_cyrillic.py to encodings\mac_cyrill
  ic.pyc
  byte-compiling C:\Python26\lib\encodings\mac_farsi.py to encodings\mac_farsi.pyc
  byte-compiling C:\Python26\lib\encodings\mac_greek.py to encodings\mac_greek.pyc
  byte-compiling C:\Python26\lib\encodings\mac_iceland.py to encodings\mac_iceland
  .pyc
  byte-compiling C:\Python26\lib\encodings\mac_latin2.py to encodings\mac_latin2.p
  yc
  byte-compiling C:\Python26\lib\encodings\mac_roman.py to encodings\mac_roman.pyc
  byte-compiling C:\Python26\lib\encodings\mac_romanian.py to encodings\mac_romani
  an.pyc
  byte-compiling C:\Python26\lib\encodings\mac_turkish.py to encodings\mac_turkish
  .pyc
  byte-compiling C:\Python26\lib\encodings\mbcs.py to encodings\mbcs.pyc
  byte-compiling C:\Python26\lib\encodings\palmos.py to encodings\palmos.pyc
  byte-compiling C:\Python26\lib\encodings\ptcp154.py to encodings\ptcp154.pyc
  byte-compiling C:\Python26\lib\encodings\punycode.py to encodings\punycode.pyc
  byte-compiling C:\Python26\lib\encodings\quopri_codec.py to encodings\quopri_cod
  ec.pyc
  byte-compiling C:\Python26\lib\encodings\raw_unicode_escape.py to encodings\raw_
  unicode_escape.pyc
  byte-compiling C:\Python26\lib\encodings\rot_13.py to encodings\rot_13.pyc
  byte-compiling C:\Python26\lib\encodings\shift_jis.py to encodings\shift_jis.pyc
  byte-compiling C:\Python26\lib\encodings\shift_jis_2004.py to encodings\shift_ji
  s_2004.pyc
  byte-compiling C:\Python26\lib\encodings\shift_jisx0213.py to encodings\shift_ji
  sx0213.pyc
  byte-compiling C:\Python26\lib\encodings\string_escape.py to encodings\string_es
  cape.pyc
  byte-compiling C:\Python26\lib\encodings\tis_620.py to encodings\tis_620.pyc
  byte-compiling C:\Python26\lib\encodings\undefined.py to encodings\undefined.pyc
  byte-compiling C:\Python26\lib\encodings\unicode_escape.py to encodings\unicode_
  escape.pyc
  byte-compiling C:\Python26\lib\encodings\unicode_internal.py to encodings\unicod
  e_internal.pyc
  byte-compiling C:\Python26\lib\encodings\utf_16.py to encodings\utf_16.pyc
  byte-compiling C:\Python26\lib\encodings\utf_16_be.py to encodings\utf_16_be.pyc
  byte-compiling C:\Python26\lib\encodings\utf_16_le.py to encodings\utf_16_le.pyc
  byte-compiling C:\Python26\lib\encodings\utf_32.py to encodings\utf_32.pyc
  byte-compiling C:\Python26\lib\encodings\utf_32_be.py to encodings\utf_32_be.pyc
  byte-compiling C:\Python26\lib\encodings\utf_32_le.py to encodings\utf_32_le.pyc
  byte-compiling C:\Python26\lib\encodings\utf_7.py to encodings\utf_7.pyc
  byte-compiling C:\Python26\lib\encodings\utf_8.py to encodings\utf_8.pyc
  byte-compiling C:\Python26\lib\encodings\utf_8_sig.py to encodings\utf_8_sig.pyc
  byte-compiling C:\Python26\lib\encodings\uu_codec.py to encodings\uu_codec.pyc
  byte-compiling C:\Python26\lib\encodings\zlib_codec.py to encodings\zlib_codec.p
  yc
  byte-compiling C:\Python26\lib\functools.py to functools.pyc
  byte-compiling C:\Python26\lib\genericpath.py to genericpath.pyc
  byte-compiling C:\Python26\lib\getopt.py to getopt.pyc
  byte-compiling C:\Python26\lib\gettext.py to gettext.pyc
  byte-compiling C:\Python26\lib\heapq.py to heapq.pyc
  byte-compiling C:\Python26\lib\inspect.py to inspect.pyc
  byte-compiling C:\Python26\lib\keyword.py to keyword.pyc
  byte-compiling C:\Python26\lib\linecache.py to linecache.pyc
  byte-compiling C:\Python26\lib\locale.py to locale.pyc
  byte-compiling C:\Python26\lib\ntpath.py to ntpath.pyc
  byte-compiling C:\Python26\lib\opcode.py to opcode.pyc
  byte-compiling C:\Python26\lib\optparse.py to optparse.pyc
  byte-compiling C:\Python26\lib\os.py to os.pyc
  byte-compiling C:\Python26\lib\os2emxpath.py to os2emxpath.pyc
  byte-compiling C:\Python26\lib\pdb.py to pdb.pyc
  byte-compiling C:\Python26\lib\pickle.py to pickle.pyc
  byte-compiling C:\Python26\lib\posixpath.py to posixpath.pyc
  byte-compiling C:\Python26\lib\pprint.py to pprint.pyc
  byte-compiling C:\Python26\lib\quopri.py to quopri.pyc
  byte-compiling C:\Python26\lib\random.py to random.pyc
  byte-compiling C:\Python26\lib\re.py to re.pyc
  byte-compiling C:\Python26\lib\repr.py to repr.pyc
  byte-compiling C:\Python26\lib\shlex.py to shlex.pyc
  byte-compiling C:\Python26\lib\sre.py to sre.pyc
  byte-compiling C:\Python26\lib\sre_compile.py to sre_compile.pyc
  byte-compiling C:\Python26\lib\sre_constants.py to sre_constants.pyc
  byte-compiling C:\Python26\lib\sre_parse.py to sre_parse.pyc
  byte-compiling C:\Python26\lib\stat.py to stat.pyc
  byte-compiling C:\Python26\lib\string.py to string.pyc
  byte-compiling C:\Python26\lib\stringprep.py to stringprep.pyc
  byte-compiling C:\Python26\lib\struct.py to struct.pyc
  byte-compiling C:\Python26\lib\subprocess.py to subprocess.pyc
  byte-compiling C:\Python26\lib\tempfile.py to tempfile.pyc
  byte-compiling C:\Python26\lib\textwrap.py to textwrap.pyc
  byte-compiling C:\Python26\lib\threading.py to threading.pyc
  byte-compiling C:\Python26\lib\token.py to token.pyc
  byte-compiling C:\Python26\lib\tokenize.py to tokenize.pyc
  byte-compiling C:\Python26\lib\traceback.py to traceback.pyc
  byte-compiling C:\Python26\lib\types.py to types.pyc
  byte-compiling C:\Python26\lib\unittest.py to unittest.pyc
  byte-compiling C:\Python26\lib\warnings.py to warnings.pyc
  *** copy extensions ***
  copying C:\Python26\DLLs\bz2.pyd -> C:\Python26\hello\dist
  copying C:\Python26\DLLs\select.pyd -> C:\Python26\hello\dist
  copying C:\Python26\DLLs\unicodedata.pyd -> C:\Python26\hello\dist
  *** copy dlls ***
  copying C:\WINDOWS\system32\python26.dll -> C:\Python26\hello\dist
  setting sys.winver for 'C:\Python26\hello\dist\python26.dll' to 'py2exe'
  copying C:\Python26\w9xpopen.exe -> C:\Python26\hello\dist
  copying C:\Python26\lib\site-packages\py2exe\run.exe -> C:\Python26\hello\dist\h
  ello.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.
  WSOCK32.dll - C:\WINDOWS\system32\WSOCK32.dll
  USER32.dll - C:\WINDOWS\system32\USER32.dll
  ADVAPI32.dll - C:\WINDOWS\system32\ADVAPI32.dll
  SHELL32.dll - C:\WINDOWS\system32\SHELL32.dll
  KERNEL32.dll - C:\WINDOWS\system32\KERNEL32.dll
  等一大串信息。
  py2exe会在当前目录下生成两个目录 build和dist.
  build里是一些py2exe运行时产生的中间文件,dist里有最终的可执行文件
  现在可以运行hello.exe了
  C:\Python26\hello\dist
  进到这目录运行Hello.exe
  即可看到输出内容.
  不过记得如果要发布到别的机器上时,library.zip、 w9xpopen.exe、python23.dll这几个文件是必须要和hello.exe在一起的。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-373880-1-1.html 上篇帖子: Python笔记——基本数据结构:列表、元组及字典 下篇帖子: Python:pygame游戏编程之旅六(游戏中的声音处理)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表