python打包exe可执行文件
一、安装pyinstaller
pip install pyinstaller
二、编写自己的应用程序
import datetime welcome = ''' ######################################## # # # PyInstaller 演示程序 # # # ######################################## ''' print(welcome) while True: exp = input('\n\n请输入一个数学运算式 [输入quit退出]:') if exp == 'quit': break try: result = eval(exp) except: print('\n!!无效的运算式') continue time = datetime.datetime.now() print(time) print(f'结果为: {result}')
三、定制运行时挂钩文件
import sys import os currentdir = os.path.dirname(sys.argv[0]) libdir = os.path.join(currentdir, "lib") print(currentdir) sys.path.append(libdir) os.environ['path'] += ';./lib'
四、cmd进入自己编写文件路径下输入
pyinstaller exefile.py --workpath e:\pybuild --distpath e:\pybuild\dist --runtime-hook="file.py"
关于pyinstaller请参考官方文档 https://pyinstaller.readthedocs.io/en/stable/usage.html