这篇文章主要是记录一下流水账。
背景
IDE使用的是Pycharm。Anaconda3安装的Python版本是3.8,在此基础上通过Pycharm安装了Opencv4.5.2.32和Mediapipe0.8.4.2.
在Pycharm的环境运行python是正常的,但是使用pyinstaller打包成exe,再运行就有问题了。打包过程:
(venv) E:\work\src\python3_src\FaceMeshProject_38>pyinstaller -F -w FaceMeshBasics.py
98 INFO: PyInstaller: 5.0.dev0
99 INFO: Python: 3.8.8
99 INFO: Platform: Windows-10-10.0.19041-SP0
100 INFO: wrote E:\work\src\python3_src\FaceMeshProject_38\FaceMeshBasics.spec
433 INFO: UPX is available.
441 INFO: Extending PYTHONPATH with paths
['E:\\work\\src\\python3_src\\FaceMeshProject_38',
'E:\\work\\src\\python3_src\\FaceMeshProject_38']
493 INFO: checking Analysis
635 INFO: checking PYZ
696 INFO: checking PKG
776 INFO: Building because E:\work\src\python3_src\FaceMeshProject_38\build\FaceMeshBasics\FaceMeshBasics.exe.manifest changed
776 INFO: Building PKG (CArchive) PKG-00.pkg
18577 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
18615 INFO: Bootloader e:\work\src\python3_src\facemeshproject_38\venv\lib\site-packages\PyInstaller\bootloader\Windows-64bit\runw.exe
18615 INFO: checking EXE
18671 INFO: Building because icon changed
18671 INFO: Building EXE from EXE-00.toc
18764 INFO: Copying icons from ['e:\\work\\src\\python3_src\\facemeshproject_38\\venv\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-windowed.ico']
18853 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
18853 INFO: Writing RT_ICON 1 resource with 3752 bytes
18853 INFO: Writing RT_ICON 2 resource with 2216 bytes
18853 INFO: Writing RT_ICON 3 resource with 1384 bytes

本文记录了使用PyInstaller将Python项目打包成exe过程中遇到的Mediapipe运行错误。问题在于打包后运行exe时找不到所需资源文件。通过分析源代码和添加缺失资源解决了问题。解决方案包括:查看错误信息、打印路径确认问题、使用pyinstaller的--add-data选项添加资源文件。
最低0.47元/天 解锁文章
456





