PyCharm 的terminal默认是系统的python环境
cd 项目名\venv\Scripts
执行activate
执行
pyinstaller -F -w MainServer.py --additional-hooks-dir hooks
命令参数
-F, –onefile 打包一个单个文件,如果你的代码都写在一个.py文件的话,可以用这个,如果是多个.py文件就别用
-D, –onedir 打包多个文件,在dist中生成很多依赖文件,适合以框架形式编写工具代码,我个人比较推荐这样,代码易于维护
-K, –tk 在部署时包含 TCL/TK
-a, –ascii 不包含编码.在支持Unicode的python版本上默认包含所有的编码.
-d, –debug 产生debug版本的可执行文件
-w,–windowed,–noconsole 使用Windows子系统执行.当程序启动的时候不会打开命令行(只对Windows有效)
-c,–nowindowed,–console
--additional-hooks-dir 指定打包的扩展库
在venv\Lib\site-packages\PyInstaller\hooks里新建一个hook-XXXX.py
from PyInstaller.utils.hooks import collect_data_files, collect_submodules
datas = collect_data_files('xxxx')
hiddenimports = collect_submodules('xxxx')