How to Fix AttributeError: module ‘enum’ has no attribute ‘intflag’

AttributeError: module ‘enum’ has no attribute ‘intflag’ error occurs when the ‘enum34’ module is installed in your system, conflicting with the default enum class.

To fix the error, “uninstalling the enum34 module” or “upgrading to a newer version of Python”.

Since Python version 3.6, the enum34 library doesn’t work with the standard library. However, you don’t need the library, so you can uninstall it.

To uninstall the enum module, you can use the below command.

pip uninstall -y enum34

# OR

python3 -m pip uninstall -y enum34

# OR

pip3 uninstall -y enum34

Flowchart

Flowchart of fixing AttributeError: module 'enum' has no attribute 'intflag'

Causes of the error

  1. Incorrect or outdated Python version
  2. Corrupted Python installation
  3. If there is a file or module in your project or Python path named enum.py, it could be shadowing the standard library’s enum module. This is a common issue when a file inadvertently has the same name as a standard library module.

Other solutions

The “intflag” attribute was introduced in Python 3.4, so if you are using an earlier version, upgrading to a newer version that includes this attribute should fix the error.

You can inspect the enum module by printing the property enum.__file__.

import enum

print(enum.__file__)

Output

/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/
                                       Versions/3.9/lib/python3.9/enum.py

If none of the suggestions helped, try to unset the PYTHONPATH environment variable.

unset PYTHONPATH

Ensure you don’t have a file named enum.py in your Python project because it would override the built-in enum module.

You have to rename or remove the file if you have one.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.