python 如何从安装了mediapipe模块的.py生成.exe?

4zcjmb1e  于 2023-05-21  发布在  Python
关注(0)|答案(2)|浏览(213)

好的,那么。我知道如何从.py创建一个.exe,但是当代码中存在mediapipe模块时,.exe将给予我this error。它说“路径不存在",但它确实存在。Here is the path codeHere is the path itself。以下是如何复制此错误:1.copy my main.py 2.pip install cv2,mediapipe and pyinstaller 3.run pyinstaller 4.copy mediapipe files to the same folder as main.exe 5.run main.exe Please help me,I have been trying to fix this for 8 hours straight and I just can't keep going.任何帮助都欢迎。提前感谢大家!
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)
ghhkc1vu

ghhkc1vu1#

1.试着在编译前把mediapipe源文件放在同一个目录下。如果上面的方法不起作用,使用pyinstallers --runtime-hook传递mediapipe编译模块,即pyc

zwghvu4y

zwghvu4y2#

使用pyinstaller添加--import argumeng并传递“mediapipe”,这将导入库并将其嵌入到可执行文件中

相关问题