How to fix Python ‘ImportError: No module named enum’

Problem:

You have code like this in Python:

from enum import Enum

But when you try to run it, you encounter this error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from enum import Enum
ImportError: No module named enum

Solution:

The enum module is only available in Python 3! You are trying to use it in Python 2.

Try running your code with Python3 (e.g. python3 myscript.py). In case that’s not possible since your project or a library is not compatible with Python 3, you can install enum34 which provides the enum package for Python 2:

sudo pip install enum34