Video Capture from webcam only works when debugging

try to use the directshow backend instead of MSMF:

vid = cv2.VideoCapture(0, CAP_DSHOW)

also, try to find more recent drivers for your hw