I've installed picamera with pip install picamera, but I can't import it. I get this error message instead:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/picamera/__init__.py", line 72, in <module>
    from picamera.exc import (
  File "/usr/lib/python3.6/site-packages/picamera/exc.py", line 41, in <module>
    import picamera.mmal as mmal
  File "/usr/lib/python3.6/site-packages/picamera/mmal.py", line 153, in <module>
    class MMAL_FOURCC_T(ct.c_uint32):
TypeError: __class__ set to <class 'picamera.mmal.MMAL_FOURCC_T'> defining 'MMAL_FOURCC_T' as <class 'picamera.mmal.MMAL_FOURCC_T'>

Has anyone an idea how to fix this?

  • Found a corresponding issue in the official Github repository. Seems like there is no solution yet. – user60021 Jan 14 '17 at 21:34
  • Yup, this is an issue in Python 3.6 itself. For now, I'd suggest just using Python 3.4 (which is the standard Python 3 on Raspbian). Could I ask what distro you're using? (I'm intrigued what distro is on 3.6 already, which has only been released recently) – Dave Jones Jan 15 '17 at 12:21
  • Arch Linux ARM is on Python 3.6. Installed it with the instructions on the site I just linked and then installed Python via pacman. – user60021 Jan 15 '17 at 14:28
  • Oh, someone's done a pacman package for picamera? That's good to know (there's an ancient ticket for that in the repo which I can tick off :-). Still, slightly surprised they're on python 3.6 mere days after it was released - certainly unusual for Linux (most distros are a lot more conservative about updates) – Dave Jones Jan 15 '17 at 14:40
  • I don't know, I've installed picamera via pip (see the original question). – user60021 Jan 15 '17 at 14:41

This is an upstream issue with Python 3.6.0 itself (see issue 29270). My hope is that there'll be some fix upstream before 3.6.x makes it into Raspbian, but in the meantime (for people on other distros like Arch which has already jumped to 3.6) the following simple patch to the installation should get things working again:

diff --git a/picamera/mmal.py b/picamera/mmal.py
index cd77362..2bd92c7 100644
--- a/picamera/mmal.py
+++ b/picamera/mmal.py
@@ -152,10 +152,7 @@ MMAL_TIME_UNKNOWN = ct.c_int64(1<<63)

 class MMAL_FOURCC_T(ct.c_uint32):
     def __eq__(self, other):
-        if isinstance(other, int):
-            return self.value == other
-        else:
-            return super(MMAL_FOURCC_T, self).__eq__(other)
+        return self.value == other

     def __str__(self):
         return ''.join(chr(self.value >> i & 0xFF) for i in range(0, 32, 8))

As noted in the associated picamera ticket (#355) this isn't a particularly good fix, and I'll include something better in 1.13, but it's the simplest patch that'll get things working again in 1.12.

Your Answer

