I just bought Raspberry Pi3 B+ and camera module. I installed Python and opencv on Pi. There was no outstanding error during installation. I connected to Raspberry pi via ssh from my mac. When I run a script, I get this error.

mmal: mmal_vc_port_enable: failed to enable port vc.null_sink:in:0(OPQV): ENOSPC
mmal: mmal_port_enable: failed to enable connected port (vc.null_sink:in:0(OPQV))0x15e4340 (ENOSPC)
mmal: mmal_connection_enable: output port couldn't be enabled
Traceback (most recent call last):
  File "test_image.py", line 8, in <module>
    camera = PiCamera()
  File "/home/pi/.virtualenvs/cv/local/lib/python3.5/site-packages/picamera/camera.py", line 433, in __init__
  File "/home/pi/.virtualenvs/cv/local/lib/python3.5/site-packages/picamera/camera.py", line 513, in _init_preview
    self, self._camera.outputs[self.CAMERA_PREVIEW_PORT])
  File "/home/pi/.virtualenvs/cv/local/lib/python3.5/site-packages/picamera/renderers.py", line 558, in __init__
  File "/home/pi/.virtualenvs/cv/local/lib/python3.5/site-packages/picamera/mmalobj.py", line 2212, in enable
    prefix="Failed to enable connection")
  File "/home/pi/.virtualenvs/cv/local/lib/python3.5/site-packages/picamera/exc.py", line 184, in mmal_check
    raise PiCameraMMALError(status, prefix)
picamera.exc.PiCameraMMALError: Failed to enable connection: Out of resources

I really have no idea whether it is the problem of connection. I enabled the camera (I also rebooted it by unplugging and plugging-in the power) and ssh by entering sudo raspi-config, did sudo apt-get update, sudo apt-get upgrade, and sudo rpi-update.

Some people suggested 'export DISPLAY=:1.0 (or 0)', and both of them bring errors saying

Unable to init server: Could not connect: Connection refused (Image:1981): Gtk-WARNING **: cannot open display: :1.0

** (Image:2003): WARNING **: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: The name org.a11y.Bus was not provided by any .service files

Now I am trying to replace the Pi and Camera module with others because they could be defective. However, before I try different devices, I would like to know what might cause such error.

A few more facts

** I also run it in a virtual environment. Python 3.5.3 and Opencv 3.4

** The wifi I connect via Macbook is a public one.

** Raspistill information is

raspistill Camera App v1.3.11

Width 3280, Height 2464, quality 85, filename (null)
Time delay 5000, Raw no
Thumbnail enabled Yes, width 64, height 48, quality 35
Link to latest frame enabled  no
Full resolution preview No
Capture method : Single capture

Preview Yes, Full screen Yes
Preview window 0,0,1024,768
Opacity 255
Sharpness 0, Contrast 0, Brightness 50
Saturation 0, ISO 0, Video Stabilisation No, Exposure compensation 0
Exposure Mode 'auto', AWB Mode 'auto', Image Effect 'none'
Flicker Avoid Mode 'off'
Metering Mode 'average', Colour Effect Enabled No with U = 128, V = 128
Rotation 0, hflip No, vflip No
ROI x 0.000000, y 0.000000, w 1.000000 h 1.000000
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
mmal: camera component couldn't be enabled
mmal: main: Failed to create camera component
mmal: Failed to run camera app. Please check for firmware updates
  • Which OS + version do you run this on? Is the camera enabled (in raspi-config or GUI configuration utility)? Can you post the output of 'vcgencmd get_camera'. It should report if the camera is enabled and detected. – Dirk Aug 8 '18 at 14:05
  • It can also mean that the camera is already in use by another program. For example you cannot use it in raspistill and a python script using picamera at the same time. – Dirk Aug 8 '18 at 14:09
  • Dirk, 1. It is High Sierra 10.13.4 Macbook Pro 2015. 2. I think the camera was enabled in raspi-config. What is GUI configuration utility? 3. When I tried, both was 1. – SSS Aug 8 '18 at 15:22
  • For the second comment, I think I saw a similar comment in a blog, but it did not explain in detail how to figure out which one is using it. During the test, I ran "raspistill -o output.jpg" several times (though I am not sure whether I did it everytime after rebooting it and before running the script). I think this could be one of the reasons. Could you please give me an instruction on how to search and terminate it? – SSS Aug 8 '18 at 15:25
  • You lost me. Where does your Pi3B+ fit in. 1. You cannot use the Pi camera on a Mac. 2. you cannot use raspistill or the picamera python module with other cameras. – Dirk Aug 8 '18 at 15:28

It is working now. I had to install Xquartz to make images and videos displayed. When it is installed and when the code is run, an image/video pops up with Xquartz.

I tried to change DISPLAY:=, raspi-update, gpu_mem=128 to gpu_mem=256 from /boot/config.txt, and so on. But my case was none of them. In my case, I could run raspistill -o output.jpg at the beginning. I could see the jpg file saved in the SD card. After then, I could not use it with an error (mmal). So I reboot it to make sure the camera module is not used.

Then, after installing Xquartz on mac and accessing it via ssh -X pi@(ip address), I could run python codes.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.