手动将python的flask程序打包成exe在windows上执行

1、安装pyinstaller工具

powershell 复制代码
(venv) PS D:\django\locallibrary> pip install pyinstaller
Collecting pyinstaller
  Downloading pyinstaller-6.11.0-py3-none-win_amd64.whl.metadata (8.4 kB)
Requirement already satisfied: setuptools>=42.0.0 in d:\django\locallibrary\venv\lib\site-packages (from pyinstaller) (75.1.0)
Collecting altgraph (from pyinstaller)
  Downloading altgraph-0.17.4-py2.py3-none-any.whl.metadata (7.3 kB)
Collecting pyinstaller-hooks-contrib>=2024.8 (from pyinstaller)
  Downloading pyinstaller_hooks_contrib-2024.9-py3-none-any.whl.metadata (16 kB)
Requirement already satisfied: packaging>=22.0 in d:\django\locallibrary\venv\lib\site-packages (from pyinstaller) (24.1)
Collecting pefile!=2024.8.26,>=2022.5.30 (from pyinstaller)
  Downloading pefile-2023.2.7-py3-none-any.whl.metadata (1.4 kB)
Collecting pywin32-ctypes>=0.2.1 (from pyinstaller)
  Downloading pywin32_ctypes-0.2.3-py3-none-any.whl.metadata (3.9 kB)
Downloading pyinstaller-6.11.0-py3-none-win_amd64.whl (1.3 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.3/1.3 MB 33.6 MB/s eta 0:00:00
Downloading pefile-2023.2.7-py3-none-any.whl (71 kB)
Downloading pyinstaller_hooks_contrib-2024.9-py3-none-any.whl (336 kB)
Downloading pywin32_ctypes-0.2.3-py3-none-any.whl (30 kB)
Downloading altgraph-0.17.4-py2.py3-none-any.whl (21 kB)
Installing collected packages: altgraph, pywin32-ctypes, pyinstaller-hooks-contrib, pefile, pyinstaller
Successfully installed altgraph-0.17.4 pefile-2023.2.7 pyinstaller-6.11.0 pyinstaller-hooks-contrib-2024.9 pywin32-ctypes-0.2.3

2、打包

powershell 复制代码
(venv) PS D:\django\locallibrary> cd .\websocket_test\
(venv) PS D:\django\locallibrary\websocket_test> pyinstaller --onefile --add-data "templates;templates" --add-data "static;static" app.py
392 INFO: PyInstaller: 6.11.0, contrib hooks: 2024.9
393 INFO: Python: 3.12.3
429 INFO: Platform: Windows-11-10.0.22631-SP0
429 INFO: Python environment: D:\django\locallibrary\venv
430 INFO: wrote D:\django\locallibrary\websocket_test\app.spec
433 INFO: Module search paths (PYTHONPATH):
['D:\\django\\locallibrary\\venv\\Scripts\\pyinstaller.exe',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python312\\python312.zip',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python312\\DLLs',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python312\\Lib',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python312',
 'D:\\django\\locallibrary\\venv',
 'D:\\django\\locallibrary\\venv\\Lib\\site-packages',
 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\setuptools\\_vendor',
 'D:\\django\\locallibrary\\websocket_test']
806 INFO: Appending 'datas' from .spec
807 INFO: checking Analysis
808 INFO: Building Analysis because Analysis-00.toc is non existent
808 INFO: Running Analysis Analysis-00.toc
808 INFO: Target bytecode optimization level: 0
808 INFO: Initializing module dependency graph...
816 INFO: Initializing module graph hook caches...
828 INFO: Analyzing base_library.zip ...
2034 INFO: Processing standard module hook 'hook-heapq.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
2103 INFO: Processing standard module hook 'hook-encodings.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
3587 INFO: Processing standard module hook 'hook-pickle.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
4761 INFO: Caching module dependency graph...
4843 INFO: Looking for Python shared library...
4852 INFO: Using Python shared library: C:\Users\Administrator\AppData\Local\Programs\Python\Python312\python312.dll
4853 INFO: Analyzing D:\django\locallibrary\websocket_test\app.py
5057 INFO: Processing pre-safe-import-module hook 'hook-typing_extensions.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
5059 INFO: SetuptoolsInfo: initializing cached setuptools info...
8643 INFO: Processing standard module hook 'hook-jinja2.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\stdhooks'
9221 INFO: Processing standard module hook 'hook-multiprocessing.util.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
9305 INFO: Processing standard module hook 'hook-xml.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
10367 INFO: Processing standard module hook 'hook-cryptography.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\stdhooks'
11958 INFO: Processing standard module hook 'hook-platform.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
12083 INFO: Processing standard module hook 'hook-sysconfig.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
12450 INFO: Processing standard module hook 'hook-difflib.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
12511 INFO: Processing pre-safe-import-module hook 'hook-importlib_metadata.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
12512 INFO: Setuptools: 'importlib_metadata' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.importlib_metadata'!
12532 INFO: Processing standard module hook 'hook-setuptools.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
12559 INFO: Processing pre-safe-import-module hook 'hook-distutils.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
12582 INFO: Processing pre-safe-import-module hook 'hook-jaraco.functools.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
12585 INFO: Setuptools: 'jaraco.functools' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.jaraco.functools'!
12599 INFO: Processing pre-safe-import-module hook 'hook-more_itertools.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
12600 INFO: Setuptools: 'more_itertools' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.more_itertools'!
12848 INFO: Processing pre-safe-import-module hook 'hook-packaging.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
12868 INFO: Processing standard module hook 'hook-packaging.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
13032 INFO: Processing pre-safe-import-module hook 'hook-jaraco.text.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
13034 INFO: Setuptools: 'jaraco.text' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.jaraco.text'!
13042 INFO: Processing standard module hook 'hook-setuptools._vendor.jaraco.text.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
13044 INFO: Processing pre-safe-import-module hook 'hook-importlib_resources.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
13044 INFO: Setuptools: 'importlib_resources' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.importlib_resources'!
13081 INFO: Processing pre-safe-import-module hook 'hook-zipp.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
13082 INFO: Setuptools: 'zipp' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.zipp'!
13106 INFO: Processing pre-safe-import-module hook 'hook-jaraco.context.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
13106 INFO: Setuptools: 'jaraco.context' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.jaraco.context'!
13114 INFO: Processing pre-safe-import-module hook 'hook-backports.tarfile.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
13114 INFO: Setuptools: 'backports.tarfile' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.backports.tarfile'!
13190 INFO: Processing standard module hook 'hook-backports.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\stdhooks'
13459 INFO: Processing pre-safe-import-module hook 'hook-tomli.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
13460 INFO: Setuptools: 'tomli' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.tomli'!
13954 INFO: Processing standard module hook 'hook-pkg_resources.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
14346 INFO: Processing pre-safe-import-module hook 'hook-platformdirs.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
14346 INFO: Setuptools: 'platformdirs' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.platformdirs'!
14467 INFO: Processing pre-safe-import-module hook 'hook-wheel.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module'
14468 INFO: Setuptools: 'wheel' appears to be a setuptools-vendored copy - creating alias to 'setuptools._vendor.wheel'!
14633 INFO: Processing standard module hook 'hook-setuptools._vendor.importlib_metadata.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks'
15096 INFO: Processing module hooks (post-graph stage)...
15463 INFO: Performing binary vs. data reclassification (19 entries)
15510 INFO: Looking for ctypes DLLs
15542 INFO: Analyzing run-time hooks ...
15545 INFO: Including run-time hook 'pyi_rth_inspect.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks'
15547 INFO: Including run-time hook 'pyi_rth_cryptography_openssl.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\rthooks'
15548 INFO: Including run-time hook 'pyi_rth_pkgutil.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks'
15550 INFO: Including run-time hook 'pyi_rth_multiprocessing.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks'
15552 INFO: Including run-time hook 'pyi_rth_setuptools.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks'
15554 INFO: Including run-time hook 'pyi_rth_pkgres.py' from 'D:\\django\\locallibrary\\venv\\Lib\\site-packages\\PyInstaller\\hooks\\rthooks'
15564 INFO: Looking for dynamic libraries
16752 INFO: Extra DLL search directories (AddDllDirectory): []
16752 INFO: Extra DLL search directories (PATH): []
17062 INFO: Warnings written to D:\django\locallibrary\websocket_test\build\app\warn-app.txt
17114 INFO: Graph cross-reference written to D:\django\locallibrary\websocket_test\build\app\xref-app.html
17142 INFO: checking PYZ
17143 INFO: Building PYZ because PYZ-00.toc is non existent
17143 INFO: Building PYZ (ZlibArchive) D:\django\locallibrary\websocket_test\build\app\PYZ-00.pyz
17873 INFO: Building PYZ (ZlibArchive) D:\django\locallibrary\websocket_test\build\app\PYZ-00.pyz completed successfully.
17924 INFO: checking PKG
17924 INFO: Building PKG because PKG-00.toc is non existent
17925 INFO: Building PKG (CArchive) app.pkg
20455 INFO: Building PKG (CArchive) app.pkg completed successfully.
20457 INFO: Bootloader D:\django\locallibrary\venv\Lib\site-packages\PyInstaller\bootloader\Windows-64bit-intel\run.exe
20458 INFO: checking EXE
20458 INFO: Building EXE because EXE-00.toc is non existent
20458 INFO: Building EXE from EXE-00.toc
20458 INFO: Copying bootloader EXE to D:\django\locallibrary\websocket_test\dist\app.exe
20739 INFO: Copying icon to EXE
21050 INFO: Copying 0 resources to EXE
21050 INFO: Embedding manifest in EXE
21365 INFO: Appending PKG archive to EXE
21376 INFO: Fixing EXE headers
21447 INFO: Building EXE from EXE-00.toc completed successfully.

3、查询编译后的目录结果

相关推荐
Tomorrow'sThinker32 分钟前
✍️ Python 批量设置 Word 文档多级字体样式(标题/正文/名称/小节)
python·自动化·word·excel
秋难降1 小时前
Python 知识点详解(三)
python·编程语言
chao_7892 小时前
二分查找篇——寻找旋转排序数组中的最小值【LeetCode】
python·线性代数·算法·leetcode·矩阵
金玉满堂@bj2 小时前
PyCharm 中 Python 解释器的添加选项及作用
ide·python·pycharm
程序员三藏2 小时前
如何使用Pytest进行测试?
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
随心点儿3 小时前
使用python 将多个docx文件合并为一个word
开发语言·python·多个word合并为一个
不学无术の码农3 小时前
《Effective Python》第十三章 测试与调试——使用 Mock 测试具有复杂依赖的代码
开发语言·python
sleepybear11133 小时前
在Ubuntu上从零开始编译并运行Home Assistant源码并集成HACS与小米开源的Ha Xiaomi Home
python·智能家居·小米·home assistant·米家·ha xiaomi home
纪伊路上盛名在3 小时前
(鱼书)深度学习入门1:python入门
人工智能·python·深度学习
夏末蝉未鸣013 小时前
python transformers笔记(TrainingArguments类)
python·自然语言处理·transformer