打包 python 程序,变成一个可执行文件

1. 安装 pyinstaller

pip3 install pyinstaller

2. 改装 matplotlib 3.1.1

现在的 matplotlib 版本都高于 3.2,而打包工具 pyinstaller需要低于 3.2 的版本,所以需要卸载 matplotlib,然后再安装低版本

pip3 uninstall matplotlib
pip3 install matplotlib==3.1.1

这个命令好像是从官网(外网)下载地址下载 matplotlib3.1.1,所以下载巨慢,得等好几分钟。

3. 安装 zeromq

实际操作中,总是报错:没有 zmq.h 这个文件。网上查了一下,如下安装:

npm install zeromq

我之前装过 npm,所以这一步成功了。如果没有装过 npm,可能还得装一下。我已经不记得 npm 是做什么的了,这一步只是照着网上的攻略打的。

4. 打包!

首先打包一次

pyinstaller -F xxx.py

然后修改配置文件 xxx.spec

vi xxx.spec

hiddenimports=[]改为hiddenimports=['matplotlib']
再打包 xxx.spec 文件:

pyinstaller -F xxx.spec

会自动生成 build, dist 文件夹,dist/xxx 即可执行文件。

5. 参考

https://blog.csdn.net/kobeyu652453/article/details/108871179
https://blog.csdn.net/u012329294/article/details/83019889

posted on 2021-10-29 09:23  luyi07  阅读(312)  评论(0编辑  收藏  举报

导航