好的,所以。我知道如何从 .py 生成 .exe,但是当代码中存在 mediapipe 模块时,.exe 会给我。它说“该路径不存在。”,但它确实存在。 和。以下是复制此错误的方法: 1.复制我的 main.py 2.pip 安装 cv2、mediapipe 和 pyinstaller 3.运行 pyinstaller 4.将 mediapipe 文件复制到与 main.exe 相同的文件夹 5.运行 main.exe 请帮助我,我已经连续 8 个小时试图解决这个问题,但我就是无法继续下去。欢迎任何帮助。先谢谢大家了!
main.py:
import cv2
import mediapipe as mp
cap = cv2.VideoCapture(0)
mpHands = mp.solutions.hands
hands = mpHands.Hands()
mpDraw = mp.solutions.drawing_utils
while True:
success, img = cap.read()
img = cv2.flip(img, 1)
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
results = hands.process(imgRGB)
if results.multi_hand_landmarks:
for handLms in results.multi_hand_landmarks:
mpDraw.draw_landmarks(img, handLms, mpHands.HAND_CONNECTIONS)
for id, lm in enumerate(handLms.landmark):
h, w, c = img.shape
cx, cy = int(lm.x * w), int(lm.y * h)
cv2.circle(img, (cx, cy), 7, (255, 0, 255), cv2.FILLED)
cv2.putText(img, str(id), (cx+10,cy+10), cv2.FONT_HERSHEY_PLAIN, 1.0, (0,0,0), 2)
cv2.imshow("Image", img)
cv2.waitKey(1)
1.在构建之前尝试将 mediapipe 源文件放在同一目录中 2.如果上述方法不起作用,请使用 pyinstallers --runtime-hook 传递 mediapipe 编译模块,即 pyc
使用 pyinstaller 添加 --import argumeng 并传递“mediapipe”,这将导入库并将其嵌入到可执行文件中
你找到解决办法了吗?对我来说没有任何作用