1. 首页 » 生活常识

Python文件打包操作详解:从基础到进阶的完整指南

一、安装第三方插件

在线安装插件:pip install PyInstaller

Python学习(七)使用PyCharm打包项目(exe可执行文件)运行

执行打包操作命令:
(1)使用默认路径存放打包文件 pyinstaller -F D:\PycharmProjects\studentSys\stuSystem.py

Python学习(七)使用PyCharm打包项目(exe可执行文件)运行

Python学习(七)使用PyCharm打包项目(exe可执行文件)运行

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         Show program version info and exit.
  --distpath DIR        Where to put the bundled app (default: ./dist)
  --workpath WORKPATH   Where to put all the temporary work files, .log, .pyz and etc. (default: ./build)
  -y, --noconfirm       Replace output directory (default: SPECPATH\dist\SPECNAME) without asking for confirmation
  --upx-dir UPX_DIR     Path to UPX utility (default: search the execution path)
  -a, --ascii           Do not include unicode encoding support (default: included if available)
  --clean               Clean PyInstaller cache and remove temporary files before building.
  --log-level LEVEL     Amount of detail in build-time console messages. LEVEL may be one of TRACE, DEBUG, INFO, WARN, ERROR, CRITICAL (default: INFO).

What to generate:
  -D, --onedir          Create a one-folder bundle containing an executable (default)
  -F, --onefile         Create a one-file bundled executable.
  --specpath DIR        Folder to store the generated spec file (default: current directory)
  -n NAME, --name NAME  Name to assign to the bundled app and spec file (default: first script's basename)

以上表格所列出的只是PyInstaller部分常用的参数,更详细的参数可通过pyinstaller -h来查看。

Python学习(七)使用PyCharm打包项目(exe可执行文件)运行


执行项目打包命令:
(1)使用默认路径存放生成后的可执行文件(exe)
        pyinstaller -F D:\PycharmProjects\studentSys\stuSystem.py

Python学习(七)使用PyCharm打包项目(exe可执行文件)运行


运行打包文件(注意:如果运行生成的exe可执行文件执行相关功能时出故障,可将可执行文件拷贝到对应的项目生成位置下,所有功能可正常运行)

Python学习(七)使用PyCharm打包项目(exe可执行文件)运行

Python学习(七)使用PyCharm打包项目(exe可执行文件)运行

声明:本文由"麦兜"发布,不代表"破站"立场,转载联系作者并注明出处:https://www.848586.cn/269431.html