I had same issue when trying to connect my webcam, I solved this by running the code on the main python kernal and not in an env