python笔记10--pyinstaller打包源码
1 介绍
本文主要介绍使用pyinstaller打包py脚本为可执行程序,后续会在此处续更其它复杂案例。
2 用法
- 安装
由于当前主流使用py3,此处不再测试py2pip3 install pyinstaller
- 单个文件打包
准备一个简单的py文件vim echo.py
#!/usr/bin/python
# -*- coding:utf-8 -*-
import time
import datetime
while True:
time.sleep(5)
print(time.time())
print(datetime.datetime.now())
打包py文件pyinstaller echo.py --onefile --clean
53 INFO: PyInstaller: 4.2
54 INFO: Python: 3.6.9
54 INFO: Platform: Linux-4.15.0-126-generic-x86_64-with-Ubuntu-18.04-bionic
55 INFO: wrote /home/xg/pyinstaller/echo.spec
58 INFO: UPX is not available.
62 INFO: Extending PYTHONPATH with paths
......
7067 INFO: Building EXE from EXE-00.toc
7068 INFO: Appending archive to ELF section in EXE /home/xg/pyinstaller/dist/echo
7089 INFO: Building EXE from EXE-00.toc completed successfully
测试效果:$ cd /home/xg/pyinstaller/dist/
$ ./echo
1612753516.5118582
2021-02-08 11:05:16.512000
3 常见问题
- 对于打包单个文件,推荐使用 -F(–onefile) 和 --clean参数。
4 说明
测试系统为ubuntu18.04,python3.6