使用pyinstaller打包有个好处就是所有依赖都打包进去了,可以随意把文件移动到别的电脑上使用
安装
pip install pyinstaller
新建一个demo.py文件
#!/usr/bin/python3 # -*- coding: utf-8 -*- print("hello world")
打开cmd或powershell
PS D:uild> pyinstaller.exe -F -c .demo.py 150 INFO: PyInstaller: 3.3.1 150 INFO: Python: 3.6.4 151 INFO: Platform: Windows-10-10.0.16299-SP0 153 INFO: wrote D:uilddemo.spec 156 INFO: UPX is not available. 162 INFO: Extending PYTHONPATH with paths ['D:\build', 'D:\build'] 162 INFO: checking Analysis 163 INFO: Building Analysis because out00-Analysis.toc is non existent 163 INFO: Initializing module dependency graph... 167 INFO: Initializing module graph hooks... 172 INFO: Analyzing base_library.zip ... 3330 INFO: running Analysis out00-Analysis.toc 3334 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable required by c:usersdowntownappdatalocalprogramspythonpython36python.exe 3434 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python.exe 3522 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python.exe 3611 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python.exe 3701 WARNING: lib not found: api-ms-win-crt-locale-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python.exe 3791 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python.exe 4004 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python36.dll 4106 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python36.dll 4195 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python36.dll 4306 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python36.dll 4401 WARNING: lib not found: api-ms-win-crt-locale-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python36.dll 4492 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python36.dll 4581 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python36.dll 4671 WARNING: lib not found: api-ms-win-crt-process-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python36.dll 4765 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python36.dll 4857 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python36.dll 4946 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python36.dll 5038 WARNING: lib not found: api-ms-win-crt-filesystem-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36python36.dll 5139 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36VCRUNTIME140.dll 5231 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36VCRUNTIME140.dll 5324 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36VCRUNTIME140.dll 5416 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36VCRUNTIME140.dll 5507 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36VCRUNTIME140.dll 5520 INFO: Caching module hooks... 5547 INFO: Analyzing D:uilddemo.py 5551 INFO: Loading module hooks... 5551 INFO: Loading module hook "hook-encodings.py"... 5695 INFO: Loading module hook "hook-pydoc.py"... 5705 INFO: Loading module hook "hook-xml.py"... 5970 INFO: Looking for ctypes DLLs 5970 INFO: Analyzing run-time hooks ... 5979 INFO: Looking for dynamic libraries 6107 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_ssl.pyd 6208 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_ssl.pyd 6303 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_ssl.pyd 6412 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_ssl.pyd 6505 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_ssl.pyd 6595 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_ssl.pyd 6686 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_ssl.pyd 6783 WARNING: lib not found: api-ms-win-crt-filesystem-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_ssl.pyd 6876 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_ssl.pyd 6976 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_ssl.pyd 7088 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLsunicodedata.pyd 7180 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLsunicodedata.pyd 7271 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLsunicodedata.pyd 7392 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLspyexpat.pyd 7486 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLspyexpat.pyd 7577 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLspyexpat.pyd 7668 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLspyexpat.pyd 7761 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLspyexpat.pyd 7874 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_hashlib.pyd 7969 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_hashlib.pyd 8062 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_hashlib.pyd 8166 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_hashlib.pyd 8255 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_hashlib.pyd 8350 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_hashlib.pyd 8440 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_hashlib.pyd 8532 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_hashlib.pyd 8622 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_hashlib.pyd 8733 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLsselect.pyd 8842 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_bz2.pyd 8933 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_bz2.pyd 9026 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_bz2.pyd 9123 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_bz2.pyd 9214 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_bz2.pyd 9330 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_lzma.pyd 9425 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_lzma.pyd 9538 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_socket.pyd 9631 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:usersdowntownappdatalocalprogramspythonpython36DLLs\_socket.pyd 9636 INFO: Looking for eggs 9636 INFO: Using Python library c:usersdowntownappdatalocalprogramspythonpython36python36.dll 9636 INFO: Found binding redirects: [] 9640 INFO: Warnings written to D:uilduilddemowarndemo.txt 9690 INFO: Graph cross-reference written to D:uilduilddemoxref-demo.html 9708 INFO: checking PYZ 9709 INFO: Building PYZ because out00-PYZ.toc is non existent 9709 INFO: Building PYZ (ZlibArchive) D:uilduilddemoout00-PYZ.pyz 10129 INFO: Building PYZ (ZlibArchive) D:uilduilddemoout00-PYZ.pyz completed successfully. 10142 INFO: checking PKG 10142 INFO: Building PKG because out00-PKG.toc is non existent 10142 INFO: Building PKG (CArchive) out00-PKG.pkg 11623 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully. 11627 INFO: Bootloader c:usersdowntownappdatalocalprogramspythonpython36libsite-packagesPyInstallerootloaderWindows-64bit un.exe 11627 INFO: checking EXE 11629 INFO: Building EXE because out00-EXE.toc is non existent 11629 INFO: Building EXE from out00-EXE.toc 11639 INFO: Appending archive to EXE D:uilddistdemo.exe 11653 INFO: Building EXE from out00-EXE.toc completed successfully. PS D:uild>
打开 dist 目录会看到已经生成了demo.exe