打包 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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM