pyinstaller打包文件

安装

pip install pyinstaller

参数

参数 含 义
-F 只生成一个exe文件
–distpath 指定生成的exe存放的目录
–workpath 指定编译中临时文件存放的目录
-i 创建一个目录包含:exe文件、依赖文件
-F 指定exe图标
-p 指定exe依赖的包、模块
-d 编译为debug模式,获取运行中的日志信息
-clean 清理编译时临时文件
-c 使用控制台
-w 使用窗口
-version-file 添加exe版本信息

例子

在我桌面有demo8.py文件

# -*- coding:utf-8 -*-
# time :2019/3/28 22:44
# author: 毛利
print('欢迎您,我是您的计算机小助手')
import psutil as ps
import time
print('本机开机的时间是:{}'.format(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(ps.boot_time()))))
print("-------------------------")
print("CPU部分")
print("-------------------------")
print('本机物理CPU个数:{}个'.format(ps.cpu_count()))
print('本机逻辑CPU个数:{}个'.format(ps.cpu_count(logical=False)))
print("-------------------------")
print('内容部分')
print("-------------------------")
print('本机内存大小为:{}个字节'.format(ps.virtual_memory().total))
print('本机已用内存大小为:{}个字节'.format(ps.virtual_memory().used))
print('本机已用内存大小占比为:{}%'.format(ps.virtual_memory().percent))
input()

注意点:

一定要在代码最后面加上input(),这样打开exe不会一散而过

在这里插入图片描述
cd 到目录
执行 pyinstaller -F demo8.py

生成日记等文件
在这里插入图片描述
找到exe
在这里插入图片描述
打开
在这里插入图片描述

发现我电脑占存挺少的

猜你喜欢

转载自blog.csdn.net/weixin_44510615/article/details/88880898