How to fix Python class ‘NameError: name ‘enum’ is not defined’

Problem:

You are trying to inherit a class from enum in Python:

class MyEnum(enum):
    X = 1
    Y = 2

But when you try to run it, you see this error message:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-15-ebcfa41a8a7c> in <module>
----> 1 class MyEnum(enum):
      2     X = 1
      3     Y = 2

NameError: name 'enum' is not defined

Solution:

You need to inherit from Enum (capital E!), not from enum! The correct syntax is

from enum import Enum

class MyEnum(Enum):
    X = 1
    Y = 2