AttributeError: module 'enum' has no attribute 'IntFlag'

Borislav Hadzhiev

2 min


# AttributeError: module 'enum' has no attribute 'IntFlag'

To solve the "AttributeError: module 'enum' has no attribute 'IntFlag'", uninstall the enum34 module by running pip uninstall -y enum34 in your terminal.

If the error persists, make sure you don't have an file in your project.

The first thing to try is to uninstall the enum34 module as it might be shadowing the official enum module.

# Uninstall the enum34 module

Open your terminal in your project's root directory and run the following command.

pip uninstall -y enum34 # ๐Ÿ‘‡๏ธ for python 3 pip3 uninstall -y enum34

Now try importing and using the Enum class from the enum module.
from enum import Enum class Sizes(Enum): SMALL = 'sm' MEDIUM = 'md' LARGE = 'lg' print( # ๐Ÿ‘‰๏ธ MEDIUM print(Sizes.MEDIUM.value) # ๐Ÿ‘‰๏ธ md

You can also use the IntEnum class.

It is the same as Enum, but its members are integers and can be used anywhere an integer can be used.
from enum import IntEnum class Numbers(IntEnum): ONE = 1 TWO = 2 THREE = 3 print(Numbers.THREE) # ๐Ÿ‘‰๏ธ Numbers.THREE print(Numbers.THREE + 10) # ๐Ÿ‘‰๏ธ 13

# Make sure you don't have a local file called

If the error persists, make sure you don't have a local file called as that would shadow the enum module.

You can access the __file__ property on the imported module to see whether it is shadowed by a local file.
import enum print(enum.__file__)

If you have a local file named, the output will be similar to the following.
# โ›”๏ธ result if shadowed by local file # /home/borislav/Desktop/bobbyhadz_python/

If you don't have a local file that shadows the enum module, you should see something similar to the following.
# โœ… result if pulling in the correct module # /usr/lib/python3.10/

# Unset the PYTHONPATH environment variable

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

Open your terminal and run the following command.


The PYTHONPATH environment variable determines where the Python interpreter looks for libraries.

Unsetting the variable sometimes fixes glitches on machines with multiple Python versions.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2023 Borislav Hadzhiev