一、下载打包工具
打包需要PyInstaller工具,如果已下载请跳过。
pip install PyInstaller
安装
出现上图情况即安装完成。
二、执行打包命令
pyinstaller -F file/file.py
将`file/file.py`换成自己打包文件的路径
执行打包
图片中红框路径为打包后生成exe文件路径。
将打包后文件存入指定路径中...
pyinstaller -F file/file.py --distpath dist --specpath spec --workpath work
file/file.py -- 为打包文件的文件路径
distpath -- 为指定exe执行文件路径
spec -- 为指定spec文件路径
work -- 为执行过程中生成的其它文件目录
三、遇到问题处理
执行打包命令时遇到如下报错,
The 'pathlib' package is an obsolete backport of a standard library package and is incompatible with PyInstaller. Please remove this package (located in /Users/eeo/anaconda3/lib/python3.10/site-packages) using
conda remove
then try again.
是因为conda安装的pathlib与pyinstaller冲突;
解决方案:
1、移除pathlib
conda remove pathlib
移除
2、更新
更新
执行完以上两步就可以了!!!