metaclass conflict

473 views
Skip to first unread message

petar.m....@gmail.com

unread,
Nov 8, 2016, 4:43:22 PM11/8/16
to OpenCV with Python Blueprints
I try to run example from ch3 and I got this error:
Traceback (most recent call last):
  File "/Users/*/opencvbook/opencv-python-blueprints/chapter3/chapter3.py", line 15, in <module>
    from gui import BaseLayout
  File "/Users/*/opencvbook/opencv-python-blueprints/chapter3/gui.py", line 15, in <module>
    class BaseLayout(wx.Frame):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/abc.py", line 87, in __new__
    cls = super(ABCMeta, mcls).__new__(mcls, name, bases, namespace)
TypeError: Error when calling the metaclass bases
    metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Michael Beyeler

unread,
Nov 8, 2016, 5:46:46 PM11/8/16
to opencv-pytho...@googlegroups.com
Aaaah, the ominous metaclass type conflict error. :)

You could try editing gui.py the following way. Change

class BaseLayout(wx.Frame):

to

class BaseLayout(Meta1):

Then add a new class right before that:

class Meta1(wx.Frame):
     pass

In addition, the 2nd edition of the book should provide a more modern solution: https://github.com/PacktPublishing/OpenCV-4-with-Python-Blueprints-Second-Edition/blob/master/wx_gui.py


Best,
Michael

Michael Beyeler

unread,
Dec 6, 2016, 1:04:00 AM12/6/16
to OpenCV with Python Blueprints
FYI, this issue has been fixed as of commit f7fe25f.



On Tuesday, November 8, 2016 at 2:46:46 PM UTC-8, Michael Beyeler wrote:
Aaaah, the ominous metaclass type conflict error. :)

You could try editing gui.py the following way. Change

class BaseLayout(wx.Frame):

to

class BaseLayout(Meta1):

Then add a new class right before that:

class Meta1(wx.Frame):
     pass


Either way seems to work fine on Ubuntu 14 / Windows 10 with Python 2.7. What platform are you on?

Let me know how it goes.

zh...@string.co

unread,
Jul 26, 2017, 10:11:52 AM7/26/17
to OpenCV with Python Blueprints
Hi Michael,
I still get the same error from the latest change on Mac with python 2.7 and latest wx

On Tuesday, 8 November 2016 22:46:46 UTC, Michael Beyeler wrote:
Aaaah, the ominous metaclass type conflict error. :)

You could try editing gui.py the following way. Change

class BaseLayout(wx.Frame):

to

class BaseLayout(Meta1):

Then add a new class right before that:

class Meta1(wx.Frame):
     pass


Either way seems to work fine on Ubuntu 14 / Windows 10 with Python 2.7. What platform are you on?

Let me know how it goes.

Michael Beyeler

unread,
Jul 29, 2017, 2:26:09 PM7/29/17
to OpenCV with Python Blueprints
That's too bad to hear, but thanks for the heads-up!

I am now using the `six` module to do a Python2/3 compatible metaclass import. Can you check e.g. Chapter 1 to see if this works for you? (Sorry, I don't have a Mac to play around with.)

Alternatively, Chapter 7 uses a different methodology (user-contributed) that is supposed to get rid of the conflict. Does that work on your platform?

Best,
Michael

Jug

unread,
Dec 21, 2018, 1:54:45 AM12/21/18
to OpenCV with Python Blueprints
Hi Michael,
I'm getting this with Chapter 1 for both python2 & python3.  Running macOS 10.13.6

Any tips would be appreciated. 
Thanks,
J

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Charles Masenas

unread,
Aug 5, 2020, 7:16:44 PM8/5/20
to OpenCV with Python Blueprints

MacOS 10.15.5, Python 3 and getting same error.  Ideas?

Michael Beyeler

unread,
Aug 6, 2020, 12:34:18 PM8/6/20
to OpenCV with Python Blueprints
The second edition of the book should provide a more modern solution: https://github.com/PacktPublishing/OpenCV-4-with-Python-Blueprints-Second-Edition/blob/master/wx_gui.py
Reply all
Reply to author
Forward
0 new messages