I'm trying to create a hand tracker using opencv, mediapipe and the time module. It works perfectly when I run it in my IDE, but when I try to turn it into an exe using the following pyinstaller command: "pyinstaller -w -F HandTrackingProgram.py", it says a bunch of stuff and at the end, gives the following error "IndexError: tuple index out of range". Here's my code:
Here's the code:
import cv2
import mediapipe as mp
import time
cap = cv2.VideoCapture(0)
mpHands = mp.solutions.hands
hands = mpHands.Hands()
mpDraw = mp.solutions.drawing_utils
pTime = 0
cTime = 0
while True:
success, img = cap.read()
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
results = hands.process(imgRGB)
if results.multi_hand_landmarks:
for handLms in results.multi_hand_landmarks:
for id, lm in enumerate(handLms.landmark):
h, w, c = img.shape
cx, cy = int(lm.x*w), int(lm.y*h)
mpDraw.draw_landmarks(img, handLms, mpHands.HAND_CONNECTIONS)
cTime = time.time()
fps = 1/(cTime-pTime)
pTime = cTime
cv2.putText(img, str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3, (255, 0, 255), 3)
cv2.imshow("Image", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
I suspect that the problem might be with the mediapipe library because when I used Python 3.11, mediapipe wouldn't install. So, I used 3.10. Mediapipe successfully installed but now, I'm facing this issue. The entire error message is too long and apparently looks like spam, so here's an image instead (this isn't the entire error message": enter image description here
**UPDATE: ** I was able to convert into an exe somehow but when I run the exe file, I get this error, " Traceback (most recent call last): File "nauru.py", line 7, in File "mediapipe\python\solutions\hands.py", line 114, in init File "mediapipe\python\solution_base.py", line 264, in init FileNotFoundError: The path does not exist. "