I'm accessing my c310 logitech webcam in python with pygame in an attempt to take pictures and save them. My final goal is to take a new picture every minute for 24 hours to make a timelapse. Here is the code to take a single picture:

import os
import pygame, sys
import time

from pygame.locals import *
import pygame.camera

#initialize pygame
cam = pygame.camera.Camera('/dev/video0')


#take a picture
image = cam.get_image()

x = 1
#save picture
alpha = 'picture%d.jpg' % (x)
pygame.image.save(image, alpha)


My issue is that after running this code from the command prompt and then attempting to run the code again (even after waiting several seconds), I get the error:

 Traceback (most recent call last):
  File "Picture1.py", line 13, in <module>
SystemError: Cannot open '/dev/video0': 16, Device or resource busy

I'm not sure why I get this error, as I use cam.stop() and pygame.quit() at the end of my code, so nothing should be using the camera after I run it. Everything is updated. Has anyone run into this error before?

  • not sure, but try also: del cam after cam.stop() – vlk Jan 8 '18 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.