手动将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、查询编译后的目录结果

相关推荐
胖哥真不错4 分钟前
Python基于TensorFlow实现GRU-Transformer回归模型(GRU-Transformer回归算法)项目实战
python·gru·tensorflow·transformer·回归模型·项目实战·gru-transformer
chusheng184011 分钟前
Python Transformer 模型的基本原理:BERT 和 GPT 以及它们在情感分析中的应用
python·bert·transformer
離離原上譜33 分钟前
python网络爬虫基础:requests库的应用
爬虫·python
weixin_466202781 小时前
第29周:实现mnist手写数字识别(Tensorflow实战第一周)
人工智能·python·tensorflow
代码猪猪傻瓜coding1 小时前
python mac vscode 脚本文件的运行
pytorch·python
梓羽玩Python1 小时前
推荐一款基于快手Kolors模型开发的虚拟试衣浏览器插件!妥妥的安排上!
人工智能·python·github
幽兰的天空2 小时前
【Python】正则表达式
python·正则表达式
小言从不摸鱼2 小时前
【Python】元组、字典与集合详解:数据容器的实战应用
人工智能·python·1024程序员节
恬淡虚无真气从之3 小时前
django中entity.save(using=)的使用
数据库·python·django