小徐同学爱学习 发表于 2025-5-14 19:20:27

python打包exe为什么路径一直报错?怎么改mediapipe的

报错内容
Traceback (most recent call last):
File "2.py", line 22, in <module>
File "cvzone\HandTrackingModule.py", line 36, in __init__
File "mediapipe\python\solutions\hands.py", line 114, in __init__
File "mediapipe\python\solution_base.py", line 234, in __init__
FileNotFoundError: The path does not exist: C:\Users\Administrator\Downloads\dist\22\_internal\mediapipe/modules/hand_landmark/hand_landmark_tracking_cpu.binarypb




https://fishc.com.cn/thread-226531-1-1.html
https://fishc.com.cn/thread-226531-1-1.html

https://fishc.com.cn/thread-226531-1-1.html这个链接里面的
,将输出的路径中的__init__.py替换为模型文件的路径,并在代码中添加这个路径。

这个是要怎么操作,我是小白,研究了好半天没懂

FishC 发表于 2025-5-14 19:21:18

解决MediaPipe模型路径问题的步骤:

1. 找到模型文件位置:
打开Python安装目录,找到:
Lib\site-packages\mediapipe\modules\hand_landmark
复制其中的 hand_landmark_tracking_cpu.binarypb 文件

2. 修改代码路径:
在调用 Hands() 的地方添加模型路径参数:

from mediapipe.python.solutions import hands

hands.Hands(
    model_path=r'mediapipe/modules/hand_landmark/hand_landmark_tracking_cpu.binarypb',
    # 其他参数保持不变...
)


3. 打包时添加资源文件(以pyinstaller为例):
创建spec文件时添加:

a = Analysis(
    ...
    datas=[
      ('源文件路径\\hand_landmark_tracking_cpu.binarypb', 'mediapipe/modules/hand_landmark')
    ],
    ...
)


4. 推荐目录结构:

[*]dist/
[*]└── your_exe/
[*]    ├── mediapipe/
[*]    │   └── modules/
[*]    │       └── hand_landmark/
[*]    │         └── hand_landmark_tracking_cpu.binarypb
[*]    └── your_exe.exe


5. 终极解决方案:
如果仍然报错,直接将模型文件复制到报错提示的路径:
C:\Users\...\dist\22\_internal\mediapipe\modules\hand_landmark\

建议使用虚拟环境打包,避免路径污染。如果仍不成功,可以尝试更新mediapipe到最新版本

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。

小徐同学爱学习 发表于 2025-5-14 19:38:11

FishC 发表于 2025-5-14 19:21
解决MediaPipe模型路径问题的步骤:

1. 找到模型文件位置:


您好,我是小白,我还是有点不太明白,这步是要怎么操作?直接将模型文件复制到报错提示的路径:
C:\Users\...\dist\22\_internal\mediapipe\modules\hand_landmark\

模型文件是(Lib\site-packages\mediapipe\modules\hand_landmark
复制其中的 hand_landmark_tracking_cpu.binarypb 文件)这个吗,复制之后,点到 File "2.py", line 22, in <module>
File "cvzone\HandTrackingModule.py", line 36, in __init__
File "mediapipe\python\solutions\hands.py", line 114, in __init__
File "mediapipe\python\solution_base.py", line 234, in __init__
这些py文件里面吗
页: [1]
查看完整版本: python打包exe为什么路径一直报错?怎么改mediapipe的