Back to Python#Tools_Powered_by_Python

See Also systemdpip

py2exe

快速的把python脚本转换为exe文件,在任何一台windows系统的电脑上运行

1. Installations

1.1. Python 2.7.x

https://www.python.org/downloads/release/python-2711/: Windows x86 MSI installer, 241bf8e097ab4e1047d9bb4f59602095

注:虚机win7是32位版本

1.2. py2exe 0.6.9

https://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/: py2exe-0.6.9.win32-py2.7.exe

注:虚机win7是32位版本

1.3. Others

2. Gen exe

2.1. Prepare your own program

C:\tmp\考勤通知>dir
 Volume in drive C has no label.
 Volume Serial Number is 78DE-0A02

 Directory of C:\tmp\考勤通知

2016/06/21  15:23    <DIR>          .
2016/06/21  15:23    <DIR>          ..
2016/06/21  14:56            18,147 gen_excel.py
2016/06/21  14:52               877 mail.ini
2016/06/16  17:50            11,712 mail.xlsx
2016/05/24  18:51            17,844 raw.xlsx
2016/06/21  09:44             1,111 README.md
2016/06/21  15:18             6,139 send_mail.py
2016/06/17  11:42             3,859 template.html
2016/06/21  15:19    <DIR>          __MACOSX
               7 File(s)         59,689 bytes
               3 Dir(s)   1,179,217,920 bytes free

2.2. Create setup script (setup.py)

from distutils.core import setup
import py2exe

setup(console=['gen_excel.py']) #send_mail.py

2.3. Run your setup script

C:\tmp\考勤通知>python setup.py py2exe
...
*** 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.

   OLEAUT32.dll - C:\Windows\system32\OLEAUT32.dll
   USER32.dll - C:\Windows\system32\USER32.dll
   SHELL32.dll - C:\Windows\system32\SHELL32.dll
   KERNEL32.dll - C:\Windows\system32\KERNEL32.dll
   ADVAPI32.dll - C:\Windows\system32\ADVAPI32.dll
   CRYPT32.dll - C:\Windows\system32\CRYPT32.dll
   WS2_32.dll - C:\Windows\system32\WS2_32.dll
   GDI32.dll - C:\Windows\system32\GDI32.dll
   ole32.dll - C:\Windows\system32\ole32.dll

2.4. Test your executable


3. Reference

MainWiki: py2exe (last edited 2016-06-20 22:11:39 by twotwo)