We know that Python is elegant and well worth learning. But Python is an explanatory language, the code needs to have a Python interpreter to execute, compared to our usual direct run EXE and other executable files a step more trouble.
So, I hope to be able to package the Python program into EXE, more convenient to use.
Pyinstaller can package Python programs into executable exe files under Windows (including Linux, Mac OS X, Solaris and AIX) and currently supports the Python 2.7 and 3.3-3.6 version.
Official website: http://www.pyinstaller.org/
Install with pip command: Pip install Pyinstaller (will depend on Pywin32 also installed, convenient)
After installation look at the version of Pyinstaller: Pyinstaller--version
Here's how to start using the Pyinstaller wrapper: python2.7+pyinstaller3.3
1. New py File: pyinstaller.py
pyinstaller.py
1 2 3 45 |
|
# Pyinstaller # pip Install Pyinstaller
Print "Hello python!" msg = input () |
2, carry out Packaging: Pyinstaller pyinstaller.py
Common option Parameters: Pyinstaller-h for more information
-F means a single executable file is generated
-W indicates that the console window is removed, which is useful in GUI interfaces. But if it is a command-line program, then remove this option!
-P means you customize the classpath that you need to load, and you don't normally use
-I represents an icon for an executable file
Pyinstaller pyinstaller.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st 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:\python27\src>Pyinstaller pyinstaller.py info:pyinstaller:3.3.1 info:python:2.7.15 Info:platform:windows-7-6.1.7601-sp1 Info:wrote C:\Python27\src\pyInstaller.spec INFO:UPX is not available. Info:extending PYTHONPATH with paths [' C:\\python27\\src ', ' c:\\python27\\src '] Info:checking Analysis Info:building analysis because OUT00-ANALYSIS.TOC is non existent Info:initializing Module Dependency Graph ... Info:initializing Module Graph Hooks ... 156 info:running Analysis Out00-analysis.toc 189 info:adding Microsoft.VC90.CRT to dependent assemblies of final executable Required by C:\python27\python.exe 1780 Info:found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1 Fc8b3b9a1e18e3b_9.0.30729.1_none_8550c6b5d18a9128.manifest 1782 Info:found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1 Fc8b3b9a1e18e3b_9.0.30729.4940_none_f47ed0f6f6564d90.manifest 1791 Info:found C:\Windows\WinSxS\Manifests\x86_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:\WINDOWS\WINSXS\MANIFESTS\X86_MICROSOFT.VC90.CRT_1FC 8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57.manifest 1825 Info:searching for file Msvcr90.dll 1825 Info:found File C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_ 9.0.30729.6161_none_50934f2ebcb7eb57\msvcr90.dll 1825 Info:searching for File Msvcp90.dll 1825 Info:found File C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_ 9.0.30729.6161_none_50934f2ebcb7eb57\msvcp90.dll 1825 Info:searching for File Msvcm90.dll 1827 Info:found File C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_ 9.0.30729.6161_none_50934f2ebcb7eb57\msvcm90.dll 1856 Info:found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1 Fc8b3b9a1e18e3b_9.0.30729.1_none_8550c6b5d18a9128.manifest 1857 Info:found C:\Windows\WinSxS\Manifests\x86_policy.9.0.microsoft.vc90.crt_1 Fc8b3b9a1e18e3b_9.0.30729.4940_none_f47ed0f6f6564d90.manifest 1858 Info:found C:\Windows\WinSxS\Manifests\x86_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:\Python27\src\pyInstaller.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:\Windows\system32\python27.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:\Python27\src\build\pyInstaller\warnpyInstaller . txt 5711 Info:graph Cross-Reference written to C:\PYTHON27\SRC\BUILD\PYINSTALLER\XR Ef-pyinstaller.html 5748 info:checking PYZ 5748 info:building PYZ Because Out00-pyz.toc is non existent 5749 info:building PYZ (zlibarchive) C:\Python27\src\build\pyInstaller\out00-PY Z.pyz 5993 info:building PYZ (zlibarchive) C:\Python27\src\build\pyInstaller\out00-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:\python27\lib\site-packages\PyInstaller\bootloader\Windo Ws-32bit\run.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:\Python27\src\build\pyInstaller\pyInstalle 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:\Users\Michael\AppData\Roaming\pyinstaller\bin Cache00_py27_32bit\python27.dll 6382 info:updating Resource Type 2 language 1033 6572 info:building COLLECT Out00-collect.toc completed successfully. |
After execution, the PyInstaller.exe is generated in the Dist of the current directory
Python Packaging-pyinstaller