pyinstaller将python编写的打卡程序打包成exe

2022-11-25,,,,

编写了一个简易的定时提醒下班打卡程序,python代码如下:

#coding:utf-8
import time
import datetime
from tkMessageBox import *
from Tkinter import *
def doSth(): while(datetime.datetime.now().hour>=18):
showinfo(title='爱心提示', message='别忘记打卡!')
time.sleep(300) def main(h=18, m=15):
while True:
now = datetime.datetime.now()
if now.hour == h and now.minute == m:
break
#每隔60秒检查一次
time.sleep(60)
doSth()
main()

代码编写好,那么怎么打包成exe应用程序呢? 找度娘知道有个pyinstaller可以打包python程序,自己查资料研究一番并成功实践,在此记录下实践的过程。

1.下载installer

知道它可以打包,那么第一步当然是下载了,下载地址为 http://www.pyinstaller.org/  ,可以选择相应的版本下载

2.安装installer

a. 将installer下载下来解压到本地如D:\PyInstaller

b. cmd打开窗口,输入命令cd D:\PyInstaller 进入D:\PyInstaller

c. 进入D:\PyInstaller后,和安装其他python模块一样输入安装命令 python setup.py install ,执行如下

d 安装pywin32

输入安装命令后执行如上图提示没有找到pywin32,所以需要安装pywin32,其下载地址为: https://sourceforge.net/projects/pywin32/files/pywin32/Build%20220/

这个下载下来是一个exe文件,安装的时候它会匹配你python路径,直接点开执行下一步直到完成就可以了。如图:

e 安装完pywin32后,再执行c步骤就可以成功了,成功后将D:\PyInstaller加入环境变量,输入pyinstaller验证是否安装成功,如下图就是安装成功了

3.用installer将python文件Timer.py打包成exe

a. 将写好的Timer.py文件保存到pyinstaller 文件夹下D:\PyInstaller

b. cmd进入到改文件夹再输入命令python pyinstaller.py -F -w Timer.py , 命令执行成功后在文件夹下可发现有个Timer文件夹,打开文件夹dist下就是exe文件。

pyinstaller将python编写的打卡程序打包成exe的相关教程结束。

《pyinstaller将python编写的打卡程序打包成exe.doc》

下载本文的Word格式文档,以方便收藏与打印。