失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python文件(.py)转换为可执行文件(.exe)操作

python文件(.py)转换为可执行文件(.exe)操作

时间:2021-03-22 00:39:17

相关推荐

python文件(.py)转换为可执行文件(.exe)操作

关于

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.py96 INFO: PyInstaller: 4.796 INFO: Python: 3.9.6104 INFO: Platform: Windows-10-10.0.19044-SP0104 INFO: wrote D:\WORK\helloworld.spec108 INFO: UPX is not available.113 INFO: Extending PYTHONPATH with paths['D:\\WORK']591 INFO: checking Analysis591 INFO: Building Analysis because Analysis-00.toc is non existent591 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.toc7036 INFO: Adding mon-Controls to dependent assemblies of final executablerequired by C:\Users\DELL\AppData\Local\Programs\Python\Python39\python.exe7107 INFO: Analyzing D:\WORK\Technology Support\From LiangHe\New OTA\ota\ComReader\helloworld.py7112 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 Tree7552 INFO: Building Tree because Tree-00.toc is non existent7554 INFO: Building Tree Tree-00.toc7665 INFO: checking Tree7665 INFO: Building Tree because Tree-01.toc is non existent7666 INFO: Building Tree Tree-01.toc7764 INFO: checking Tree7764 INFO: Building Tree because Tree-02.toc is non existent7764 INFO: Building Tree Tree-02.toc7779 INFO: Looking for ctypes DLLs7789 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 libraries8022 INFO: Looking for eggs8022 INFO: Using Python library C:\Users\DELL\AppData\Local\Programs\Python\Python39\python39.dll8023 INFO: Found binding redirects:[]8030 INFO: Warnings written to D:\WORK\build\helloworld\warn-helloworld.txt8059 INFO: Graph cross-reference written to D:\WORK\build\helloworld\xref-helloworld.html8068 INFO: checking PYZ8068 INFO: Building PYZ because PYZ-00.toc is non existent8069 INFO: Building PYZ (ZlibArchive) D:\WORK\build\helloworld\PYZ-00.pyz8432 INFO: Building PYZ (ZlibArchive) D:\WORK\build\helloworld\PYZ-00.pyz completed successfully.8444 INFO: checking PKG8444 INFO: Building PKG because PKG-00.toc is non existent8445 INFO: Building PKG (CArchive) helloworld.pkg9684 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.exe9686 INFO: checking EXE9686 INFO: Building EXE because EXE-00.toc is non existent9686 INFO: Building EXE from EXE-00.toc9686 INFO: Copying bootloader EXE to D:\WORK\dist\helloworld.exe9734 INFO: Copying icon to EXE9735 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 bytes9780 INFO: Writing RT_ICON 1 resource with 3752 bytes9781 INFO: Writing RT_ICON 2 resource with 2216 bytes9789 INFO: Writing RT_ICON 3 resource with 1384 bytes9789 INFO: Writing RT_ICON 4 resource with 37019 bytes9790 INFO: Writing RT_ICON 5 resource with 9640 bytes9790 INFO: Writing RT_ICON 6 resource with 4264 bytes9791 INFO: Writing RT_ICON 7 resource with 1128 bytes9793 INFO: Copying 0 resources to EXE9793 INFO: Emedding manifest in EXE9794 INFO: Updating manifest in D:\WORK\dist\helloworld.exe9839 INFO: Updating resource type 24 name 1 language 09841 INFO: Appending PKG archive to EXE10839 INFO: Building EXE from EXE-00.toc completed successfully.

在dist文件夹里有exe文件:

双击运行显示结果:

如果觉得《python文件(.py)转换为可执行文件(.exe)操作》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。