on my Raspberry Pi, I come across unusual behavior regarding the use of the PiCamera module.
The following code runs smoothly when it is run from IDLE (F5) or from the command line ($ python test.py)
import picamera if __name__ == "__main__": camera=picamera.PiCamera() camera.close()
But when I put the camera object in a class, the code will only work when I start with IDLE (F5):
import picamera class VF: def __init__(self): self.camera = picamera.PiCamera() def __del__(self): self.camera.close() if __name__ == "__main__": myvf = VF()
When I run the above code from the command line, I get the following error message:
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
Traceback (last last call): File "test.py", line 14, in myvf = VF ()
File "test.py", line 6, in init self.camera = picamera.PiCamera ()
File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 379, in init camera_num, self.STEREO_MODES [stereo_mode], stereo_decimate)
File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 505, in _init_camera prefix = "Unable to enable camera component")
File "/usr/lib/python2.7/dist-packages/picamera/exc.py", line 133, in mmal_check raise PiCameraMMALError (status, prefix)
picamera.exc.PiCameraMMALError: the camera component cannot be turned on: From resources (except memory)
The camera module works correctly, I just stripped the code to the smallest possible size. Does anyone know this problem or a similar problem and can probably provide a solution? Python is 2.7 and the Raspberry Rasbiab system has been completely updated. Thanks in advance.