pyinstaller 打包成 exe

生成 spec 和可执行文件:

pyinstaller --onefile your_file.py

如果需要修改生成的spec文件,则后续可以这样运行:

pyinstaller -F your_file.spec

 

 


遇到2个问题:

1. 报错 找不到 mkl_pgi_thread.1.dll, 可以从python安装目录里拷到 dist 目录下和 exe放一起,更好的办法是重新安装最新版 numpy (pip install -U numpy)

2. 报错 Pyinstaller Matplotlib [Errno 2] No such file or directory: 'C:\\Users\\Tobi\\AppData\\Local\\Temp\\_MEI142562\\matplotlib\\mpl-data\\matplotlibrc',我开始安装的pyinstaller是3.6, 后来换成4.5, 都不行,解决方法是重新安装了pyinstaller (pip install -U pyinstaller==4.3)

 3. 此外, 用pyinstaller 打包yolov5的代码,结果遇到这个问题,还没搞懂原因.

更新- 原因为打包成的exe文件会解压出python脚本,默认放在C盘,然后再运行,这时候运行文件在C盘,但是当前目录又是E盘,这样就relpath 算不出相对路径,因为盘不同。

 

 

Ref:

http://events.jianshu.io/p/50329d01b6cf

https://www.cnblogs.com/the3times/p/12386007.html

https://blog.csdn.net/wanjuan1998/article/details/118088373

posted @ 2021-09-20 20:13  mashuai_191  阅读(120)  评论(0编辑  收藏  举报