Why Python 3.6.1 throws AttributeError module 'enum' has no attribute 'IntFlag'?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The error AttributeError: module 'enum' has no attribute 'IntFlag' occurs when Python imports a third-party package named enum instead of the standard library's enum module. This typically happens because a pip-installed package called enum34 (a backport for Python 2) shadows the built-in enum module, or because a file named enum.py exists in your project directory. The fix is to uninstall enum34 and remove any local enum.py file.
The Error
IntFlag was added to the standard library enum module in Python 3.6. If Python finds a different enum module first (one that does not have IntFlag), this error occurs.
Fix 1: Uninstall enum34
The most common cause is having the enum34 package installed:
enum34 is a backport of the enum module for Python 2 and Python 3.3 or earlier. It should NOT be installed on Python 3.4+, as it shadows the built-in enum module which has more features (including IntFlag).
Check if enum34 is installed
Fix 2: Remove Local enum.py File
Check if you have a file named enum.py in your project or current directory:
Also check for a compiled __pycache__/enum.cpython-*.pyc file and delete it:
Fix 3: Check import Order
Verify which enum module Python is loading:
If the path points to site-packages or your local directory, that is the wrong module.
Fix 4: Fix in Virtual Environment
Fix 5: Remove enum34 from requirements.txt
Check your requirements.txt or setup.py for enum34:
Some older packages list enum34 as a dependency. If removing it breaks another package, update that package to a newer version that does not require enum34.
Understanding Python's enum Module
IntFlag extends Flag and int, allowing both flag-style combinations and integer comparisons. It was added in Python 3.6 and is not available in the enum34 backport.
Debugging Checklist
Common Pitfalls
- Installing enum34 on Python 3.6+:
enum34overwrites the standard library'senummodule with an older version that lacksIntFlag,Flag, andauto(). Never installenum34on Python 3.4 or later. - A dependency pulling in enum34: Some older packages declare
enum34as a dependency unconditionally. Checkpip show <package>for your installed packages to find which one requiresenum34, and update or replace it. - Local
enum.pyorenum/directory: Python searches the current directory before the standard library. A file namedenum.pyor a directory namedenum/in your project shadows the built-in module. - Cached
.pycfiles: After removing a localenum.py, the compiled__pycache__/enum.cpython-*.pycmay still be loaded. Delete the__pycache__directory or the specific.pycfile. - Conda environments: In Conda,
enum34can be installed through Conda channels even on Python 3.6+. Useconda list | grep enumandconda remove enum34to fix.
Summary
- Uninstall
enum34withpip uninstall enum34— it shadows the standard library on Python 3.4+ - Remove any local
enum.pyfile orenum/directory from your project - Check which
enummodule is loaded withimport enum; print(enum.__file__) IntFlagis part of the standard libraryenummodule since Python 3.6- Remove
enum34fromrequirements.txtand use conditional dependencies if needed for backward compatibility

