我知道Python很优雅,值得学习。 但是,Python是一种描述性语言,执行代码需要Python解释器,比我们平时直接执行exe等可执行文件要麻烦得多。
所以,我想把Python程序打包成exe,让它有多好用。
PyInstaller可以将Python程序打包为可在Windows (当然也包括Linux、Mac OS X和Solaris and AIX )上运行的EXE文件,目前python 2.7 and 3.3-3.6 bar
使用pip命令安装: pipinstallpyinstaller (因为依赖py win32也可以安装,所以很方便) )。
安装后,让我们看看pyinstaller的版本。 py installer--版本
接下来,开始使用pyinstaller软件包。 python2.7 pyinstaller3.3
1、新的py文件: pyInstaller.py
pyInstaller.py
1
2
3
4
5
#pyinstaller
# pipinstallpyinstallerprint ' hello python!'
msg=input ()
2、运行打包: pyinstallerpyInstaller.py
常规可选参数:有关详细信息,请参阅pyinstaller -h
-F意味着生成单个可执行文件
-w表示要删除控制台窗口。 这在GUI界面中非常有用。 但是,如果是命令行程序的话,就删除这个选项吧。
-p表示您自己定制要加载的类路径,通常不可用
-i表示可执行文件的图标
pyinstallerpyInstaller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
c :python 27srcpyinstallerpyinstaller.py
60 info : py installer :3.3.1
60INFO:Python:2.7.15
60 info :平台: windows-7-6.1.7601-SP1
61 info : wrotec :python 27srcpy installer.spec
62信息:更新可用性。
6 info :扩展pythonpathwithpaths
[‘C:\Python27\src‘,‘c :\ python 27\ src‘’]
68 info :检查分析
68 info : buildinganalysisbecauseout 00-analysis.tocisnonexistent
9 info :初始化模块.
71 info :初始化莫
dule graph hooks...156 INFO: running Analysis out00-Analysis.toc
189 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable
required by c:python27python.exe
1780 INFO: Found C:WindowsWinSxSManifestsx86_policy.9.0.microsoft.vc90.crt_1
fc8b3b9a1e18e3b_9.0.30729.1_none_8550c6b5d18a9128.manifest
1782 INFO: Found C:WindowsWinSxSManifestsx86_policy.9.0.microsoft.vc90.crt_1
fc8b3b9a1e18e3b_9.0.30729.4940_none_f47ed0f6f6564d90.manifest
1791 INFO: Found C:WindowsWinSxSManifestsx86_policy.9.0.microsoft.vc90.crt_1
fc8b3b9a1e18e3b_9.0.30729.6161_none_f480bfaef65491a5.manifest
1823 INFO: Searching for assembly x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30
729.6161_none ...
1824 INFO: Found manifest C:WindowsWinSxSManifestsx86_microsoft.vc90.crt_1fc
8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57.manifest
1825 INFO: Searching for file msvcr90.dll
1825 INFO: Found file C:WindowsWinSxSx86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_
9.0.30729.6161_none_50934f2ebcb7eb57msvcr90.dll
1825 INFO: Searching for file msvcp90.dll
1825 INFO: Found file C:WindowsWinSxSx86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_
9.0.30729.6161_none_50934f2ebcb7eb57msvcp90.dll
1825 INFO: Searching for file msvcm90.dll
1827 INFO: Found file C:WindowsWinSxSx86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_
9.0.30729.6161_none_50934f2ebcb7eb57msvcm90.dll
1856 INFO: Found C:WindowsWinSxSManifestsx86_policy.9.0.microsoft.vc90.crt_1
fc8b3b9a1e18e3b_9.0.30729.1_none_8550c6b5d18a9128.manifest
1857 INFO: Found C:WindowsWinSxSManifestsx86_policy.9.0.microsoft.vc90.crt_1
fc8b3b9a1e18e3b_9.0.30729.4940_none_f47ed0f6f6564d90.manifest
1858 INFO: Found C:WindowsWinSxSManifestsx86_policy.9.0.microsoft.vc90.crt_1
fc8b3b9a1e18e3b_9.0.30729.6161_none_f480bfaef65491a5.manifest
1859 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0,
30729, 6161)
2138 INFO: Caching module hooks...
2144 INFO: Analyzing C:Python27srcpyInstaller.py
2144 INFO: Loading module hooks...
2146 INFO: Loading module hook "hook-encodings.py"...
5555 INFO: Looking for ctypes DLLs
5555 INFO: Analyzing run-time hooks ...
5561 INFO: Looking for dynamic libraries
5680 INFO: Looking for eggs
5682 INFO: Using Python library C:Windowssystem32python27.dll
5682 INFO: Found binding redirects:
[BindingRedirect(name=u‘Microsoft.VC90.CRT‘, language=None, arch=u‘x86‘, oldVers
ion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 6161), publicKeyToken=u‘1fc8b3b9a
1e18e3b‘)]
5685 INFO: Warnings written to C:Python27srcbuildpyInstallerwarnpyInstaller
.txt
5711 INFO: Graph cross-reference written to C:Python27srcbuildpyInstallerxr
ef-pyInstaller.html
5748 INFO: checking PYZ
5748 INFO: Building PYZ because out00-PYZ.toc is non existent
5749 INFO: Building PYZ (ZlibArchive) C:Python27srcbuildpyInstallerout00-PY
Z.pyz
5993 INFO: Building PYZ (ZlibArchive) C:Python27srcbuildpyInstallerout00-PY
Z.pyz completed successfully.
6028 INFO: checking PKG
6029 INFO: Building PKG because out00-PKG.toc is non existent
6029 INFO: Building PKG (CArchive) out00-PKG.pkg
6048 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
6051 INFO: Bootloader c:python27libsite-packagesPyInstallerbootloaderWindo
ws-32bitrun.exe
6051 INFO: checking EXE
6051 INFO: Building EXE because out00-EXE.toc is non existent
6052 INFO: Building EXE from out00-EXE.toc
6052 INFO: Appending archive to EXE C:Python27srcbuildpyInstallerpyInstalle
r.exe
6054 INFO: Building EXE from out00-EXE.toc completed successfully.
6060 INFO: checking COLLECT
6061 INFO: Building COLLECT because out00-COLLECT.toc is non existent
6063 INFO: Building COLLECT out00-COLLECT.toc
6073 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 307
29, 6161)
6291 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 307
29, 6161)
6297 INFO: Updating manifest in C:UsersMichaelAppDataRoamingpyinstallerbin
cache00_py27_32bitpython27.dll
6382 INFO: Updating resource type 24 name 2 language 1033
6572 INFO: Building COLLECT out00-COLLECT.toc completed successfully.
执行完毕后,会在当前目录的dist 中生成pyInstaller.exe