11

For starting the camera I am doing

>>> import picamera 
>>> camera = picamera.PiCamera()
mmal: mmal_vc_component_enable: failed to enable compononent : ENOSPC
Traceback (most recent call last):
  File "<stdin>", line, in <module>
  ...
  ...
picamera.exc.PiCameraMMALError: Camera component couldn't be enabled: Out of resources (other than memory)

I checked lot of answers which told to update the package and I did that but nothing seems to help. IS my camera gone or is there some solution?

Coderaemon
  • 465
  • 1
  • 11
  • 21
  • 1
    Have you enabled the camera in raspi-config? – Werner Kvalem Vesterås Jan 14 '15 at 07:49
  • yes I did by going in config sudo raspi-config – Coderaemon Jan 14 '15 at 10:07
  • 1
    Ensure that your camera is connected the right way, like this: http://www.adafruit.com/blog/wp-content/uploads/2014/01/1646pi_LRG-600x461.jpg – Werner Kvalem Vesterås Jan 14 '15 at 10:09
  • Yes camera is right. The power red LED is on. – Coderaemon Jan 14 '15 at 10:18
  • 1
    Have you tried operating your camera from the command line with raspistill? If that is not working, maybe you should consult the camera trouble shouting guide: http://www.raspberrypi.org/documentation/troubleshooting/hardware/camera.md – Werner Kvalem Vesterås Jan 14 '15 at 10:50
  • This happened to me the first time too -- or rather, the equivalent w/ raspistill (exited with an ENOSPC error). So if raspistill doesn't work either, try raspi-config again and reboot. I believe that it didn't complete properly the first time WRT some stuff in /boot/config.txt. If that works, please add it as an answer to your own question :) – goldilocks Jan 14 '15 at 13:27

14 Answers14

12

As an addition to the other answers, I just want to mention that the cause for this error could also be that another process is currently using the camera.

Robin
  • 251
  • 2
  • 7
  • 2
    I think you could be right. I started to get this error after interrupting a camera script that wasn't responding (using CTRL-C). Camera was working fine prior to this. So how do I release/reset the camera so it works again? – Bill Jul 02 '16 at 04:19
  • In my case, motion library was using the camera. Running sudo service motion stop solved my problem – Laura Corssac Apr 28 '20 at 10:55
7

The Raspberry Pi Camera Module uses the onboard GPU and its memory. Since your error message mentions being out of resources, consider adding at least (and possibly more than) the recommended minimum of 128MB to the GPU's allotment.

To change it:

sudo raspi-config

select: Advanced options -> Memory split -> and set at least 128MB

Some users report this message disappearing after changing the GPU memory allotment to 256MB from 128MB.

M. Mills
  • 35
  • 3
vlk
  • 291
  • 5
  • 6
4

I ran into this same problem with the Rasp Pi 3. I started a python script that would take 1 image per second for a minute. I hit ctrl-z to interrupt script execution about halfway through. When I tried to run the script again, I got this error, although it appeared that no other scripts were using the camera.

The fix: Enter "ps -a" to list all of the currently running processes. Look for one that says "python" or "python3" in the output, like this:
PID TTY TIME CMD 1218 tty1 00:00:00 bash 2203 pts/0 00:00:00 python 8960 pts/1 00:00:00 ps

Use the command "kill -KILL [PID#]" to stop the python process. For this case, the command was "kill -KILL 2203".

After doing this, use "ps -a" again to make sure the python process is not listed.

This cleared up the problem for me, and I was able to run my script again without any issues.

Hope this helps.

bmward
  • 41
  • 4
  • Ctrl-Z just pauses execution. Use Ctrl-C to abort the script. To kill a process paused by Ctrl-Z, you can use kill %1, at least in Bash. – moi Feb 28 '21 at 11:15
4

The solution is to ensure that the line, camera = PiCamera() is outside of any loop or function.

If the line camera = PiCamera() is called every time your function runs then the Camera runs out of memory.

camera = PiCamera()

def Take_an_Image():

    camera.resolution = (1024, 768)
    camera.start_preview()
    camera.capture("Test")
Aurora0001
  • 6,308
  • 3
  • 23
  • 38
TeCoEd
  • 41
  • 1
  • It doesn't appear that this specific error was due to running out of memory (the error was "Camera component couldn't be enabled: Out of resources (other than memory)"), and the OP didn't declare their camera in a loop, but this is good advice if someone does run out of memory. – Aurora0001 Jan 07 '18 at 12:12
3

Follow this order of commands:

  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo rpi-update

The last one is very important if you bought your Raspberry a long time ago, AND if you want some new features.

alcor
  • 131
  • 4
  • 1
    Note that the rpi-update is now deprecated: https://picamera.readthedocs.io/en/release-1.10/install3.html and https://www.raspberrypi.org/documentation/raspbian/updating.md – Unsliced May 03 '16 at 17:55
3

For anyone else with this problem... if the light is on at boot then you really might have the wrong ribbon cable port! The cable will fit nicely into the LCD port and the light will turn on and everything. But you will get the error saying to enable the device.

Werner pointed this out: https://blog.adafruit.com/wp-content/uploads/2014/01/1646pi_LRG-600x461.jpg

bmidgley
  • 31
  • 2
2

In my code there was a silly bug that gave raise to this error: I opened the camera once, but intentionally tried to open it again when the user clicks a hardware button. Closing the camera before the second call to PiCamera() resolved the problem.

1

In addition to alcor's answer, make sure you run raspi-config, and choose option 5 after you boot up, to enable camera support.

I think you might need to use sudo

cometbill
  • 109
  • 3
1

So it turns out that Camera port of my Raspberry Pi had some problem. Replaced the Pi, camera is working smoothly.

Coderaemon
  • 465
  • 1
  • 11
  • 21
1

I ran into same issue. I realized that since I was broadcasting video via httpd, I could not make use of the images via Python. I had to choose to either let the Python script access the images or let the Apache server make video available via browser. Only one process can access the camera at a time.

1

I had this ressource issue, it turned out the fonction camera.capture(filename) was the problem, because the file already existed.

user72314
  • 11
  • 1
1

For my case, having the same error, replacing the camera module fixed it. I was able to reliably reproduce the error by switching back and forth between good and bad camera modules. My code did not suffer from the problems others pointed out. So it seems hardware problems can cause this exception too.

The exception was:

picamera.exc.picamerammalerror: failed to enable connection: out of resources

Picamera version is 1.13 and the camera module is v2.1

Greenonline
  • 2,740
  • 4
  • 23
  • 36
ayush3504
  • 111
  • 1
  • I had an issue with a defective ribbon giving the same error. I am guessing that this part in particular is the most damage prone part of the camera module —luckily it's the easiest to fix. – Matteo Ferla Dec 31 '20 at 15:05
0

You will get this error if your button is not properly connected. The Pi will think the button is pressed and continually try to take photos, hence you will be out of resources!

Make sure your button is plugged into the correct GPIO pin and then continue to other methods of debugging.

Aurora0001
  • 6,308
  • 3
  • 23
  • 38
0

Just my penny worth.. I wrote a small program that takes a sequence of pics. It worked fine in IDLE, but from command line came up with exact same error being out of resources. The problem was fixed by adding camera.close() after except KeyboardInterrupt:, ie Ctrl+C (in the python shell). for when you need to break out of a loop.

Nick
  • 1
  • Thanks for your answer. Because it's your first answer, I've been prompted by the system to review it, and make any comments that might help you improve it. I'm struggling to understand what your proposed answer is. Please try to be more specific; e.g. provide some code that you feel will resolve the issue. I'd also recommend you read "How to write a good answer". Please consider these suggestions, and edit your answer accordingly. – Seamus Sep 16 '18 at 18:13