天早上想起,Python项目如何打包发布呢?因此特意学习了下

比较好用的为pyinstaller,可以支持在window和linux下使用

1.安装

pip install pyinstaller

2.使用

格式:

  pyinstaller -F 待打包文件名

eg:

pie.py

import matplotlib.pyplot as plt
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
sizes = [15, 30, 45, 10]
explode = (0, 0.1, 0, 0)

fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
        shadow=True, startangle=90)
ax1.axis('equal') 

plt.show()

打包

pyinstaller -F pie.py

在当前的目录下,将会生成两个文件夹:build和dist,还有pie.spec

dist里面就是所有可执行文件

.spec告诉pyinstaller如何打包的配置文件

Python打包发布_打包发布

双击dist下的exe

Python打包发布_ico_02

 Python打包发布_配置文件_03

 指定图标

pyinstaller -F -i icon.ico pie.py

Python打包发布_ico_04