关于
Python学习笔记(15)-Python代码转换为exe可执行程序详解_熊猫大哥大-CSDN博客_python转化为exe
Python 将.py转换为.exe详解_tangdaxue43的博客-CSDN博客_py转换成exe
的一些小心得;
下载PyInstaller
pip install pyinstaller
结果如下:意思是已经装上了。
下载pywin32
先看看python目录C:\Users\DELL\AppData\Local\Programs\Python\Python39\Scripts里有没有pywin32_postinstall.py,如果有直接在这个目录下执行:
python pywin32_postinstall.py -install
再看看目录里的内容,确定有没有需要的pyinstaller.exe,执行ls,结果如下图:
ls
可以把这个pyinstaller.exe复制出来到任意文件夹,直接用,保证pyinstaller.exe和带转换的.py同在一个文件夹即可。
开始转换
自己编写一个.py文件,其实txt文件就可以,把.txt改成.py重命名。和pyinstaller.exe放在一个文件夹里。
print('hello world!')
input()
执行(exe文件名前面的.\是执行的意思),注意文件名称。
.\pyinstaller.exe -F .\helloworld.py
PS D:\WORK> .\pyinstaller.exe -F .\helloworld.py
96 INFO: PyInstaller: 4.7
96 INFO: Python: 3.9.6
104 INFO: Platform: Windows-10-10.0.19044-SP0
104 INFO: wrote D:\WORK\helloworld.spec
108 INFO: UPX is not available.
113 INFO: Extending PYTHONPATH with paths
['D:\\WORK']
591 INFO: checking Analysis
591 INFO: Building Analysis because Analysis-00.toc is non existent
591 INFO: Initializing module dependency graph...
594 INFO: Caching module graph hooks...
616 INFO: Analyzing base_library.zip ...
3492 INFO: Processing pre-find module path hook distutils from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
3493 INFO: distutils: retargeting to non-venv dir 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib'
6888 INFO: Caching module dependency graph...
7023 INFO: running Analysis Analysis-00.toc
7036 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by C:\Users\DELL\AppData\Local\Programs\Python\Python39\python.exe
7107 INFO: Analyzing D:\WORK\Technology Support\From LiangHe\New OTA\ota\ComReader\helloworld.py
7112 INFO: Processing module hooks...
7112 INFO: Loading module hook 'hook-difflib.py' from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
7114 INFO: Loading module hook 'hook-distutils.py' from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
7114 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
7115 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
7196 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
7198 INFO: Loading module hook 'hook-lib2to3.py' from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
7262 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
7264 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
7265 INFO: Loading module hook 'hook-sysconfig.py' from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
7267 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
7268 INFO: Loading module hook 'hook-xml.py' from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
7368 INFO: Loading module hook 'hook-_tkinter.py' from 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks'...
7552 INFO: checking Tree
7552 INFO: Building Tree because Tree-00.toc is non existent
7554 INFO: Building Tree Tree-00.toc
7665 INFO: checking Tree
7665 INFO: Building Tree because Tree-01.toc is non existent
7666 INFO: Building Tree Tree-01.toc
7764 INFO: checking Tree
7764 INFO: Building Tree because Tree-02.toc is non existent
7764 INFO: Building Tree Tree-02.toc
7779 INFO: Looking for ctypes DLLs
7789 INFO: Analyzing run-time hooks ...
7790 INFO: Including run-time hook 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
7798 INFO: Including run-time hook 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
7805 INFO: Including run-time hook 'C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
7814 INFO: Looking for dynamic libraries
8022 INFO: Looking for eggs
8022 INFO: Using Python library C:\Users\DELL\AppData\Local\Programs\Python\Python39\python39.dll
8023 INFO: Found binding redirects:
[]
8030 INFO: Warnings written to D:\WORK\build\helloworld\warn-helloworld.txt
8059 INFO: Graph cross-reference written to D:\WORK\build\helloworld\xref-helloworld.html
8068 INFO: checking PYZ
8068 INFO: Building PYZ because PYZ-00.toc is non existent
8069 INFO: Building PYZ (ZlibArchive) D:\WORK\build\helloworld\PYZ-00.pyz
8432 INFO: Building PYZ (ZlibArchive) D:\WORK\build\helloworld\PYZ-00.pyz completed successfully.
8444 INFO: checking PKG
8444 INFO: Building PKG because PKG-00.toc is non existent
8445 INFO: Building PKG (CArchive) helloworld.pkg
9684 INFO: Building PKG (CArchive) helloworld.pkg completed successfully.
9686 INFO: Bootloader C:\Users\DELL\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
9686 INFO: checking EXE
9686 INFO: Building EXE because EXE-00.toc is non existent
9686 INFO: Building EXE from EXE-00.toc
9686 INFO: Copying bootloader EXE to D:\WORK\dist\helloworld.exe
9734 INFO: Copying icon to EXE
9735 INFO: Copying icons from ['C:\\Users\\DELL\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
9780 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
9780 INFO: Writing RT_ICON 1 resource with 3752 bytes
9781 INFO: Writing RT_ICON 2 resource with 2216 bytes
9789 INFO: Writing RT_ICON 3 resource with 1384 bytes
9789 INFO: Writing RT_ICON 4 resource with 37019 bytes
9790 INFO: Writing RT_ICON 5 resource with 9640 bytes
9790 INFO: Writing RT_ICON 6 resource with 4264 bytes
9791 INFO: Writing RT_ICON 7 resource with 1128 bytes
9793 INFO: Copying 0 resources to EXE
9793 INFO: Emedding manifest in EXE
9794 INFO: Updating manifest in D:\WORK\dist\helloworld.exe
9839 INFO: Updating resource type 24 name 1 language 0
9841 INFO: Appending PKG archive to EXE
10839 INFO: Building EXE from EXE-00.toc completed successfully.
在dist文件夹里有exe文件:
双击运行显示结果: