AttributeError: module ‘enum’ has no attribute ‘IntFlag’ in Python

AttributeError: module ‘enum’ has no attribute ‘IntFlag’ in Python is a popular error in Python, the error occurs because the enum in this case is not the standard library enum module.

In this article I will talk about how I replicated and solved this error, I will also present and explain in detail how other developers solved this issue using other solutions.

Explaining : AttributeError: module ‘enum’ has no attribute ‘IntFlag’ in Python

This error occurs usually after a fresh installation or at least in my case this was my experience.

It occurs when you try running any code on Python 3.

This is how the error will look like for most of you :

                                                                       #
AttributeError: module 'enum' has no attribute 'IntFlag'
      ###############
 /Library/Frameworks/Python.framework/Versions/3.6/bin/python3  
Failed to import the site module  
Traceback (most recent call last):  
....
    class RegexFlag(enum.IntFlag):  
                                                                       #

Hours passed after I first got the error, I searched and tested and tried everything, bellow I present to you the solution that worked for me.

Solution 1 : unset PYTHONPATH

This is the solution that worked for me, I was able to solve this problem by unsetting PYTHONPATH.

In order to unset PYTHONPATH please run the code bellow.

                                                                       #
$ unset PYTHONPATH
                                                                       #

You do not have to restart your computer, I did not have to, just close the prompt and open it again.

If this did not work, please restart the computer after executing the code, if even after the restart you get the error, then the solution did not work.

Other developers faced the same problem and solved it with other solutions described bellow.

Solution 2 : remove enum34 from your machine

Sometimes the error occurs when you have the package enum34 installed in your environment, the package enum34 usually overrides the built-in enum in Python which causes the problem.

The solution is to remove enum34 from your machine, you can do that by running the code bellow.

                                                                       #
pip uninstall -y enum34
                                                                       #

Solution 3 : remove Google App Engine Support in pycharm preferences

A lot of people have this issue while running pycharm and Google App Engine, you can get rid of the error by removing “Google App Engine Support” in pycharm preferences.

You have to open pycharm preferences with the UI and uncheck Google app engine support.

The error will be gone. If your error is not related to pycharm try the solution bellow.

Solution 4 : only if you have both Python 2 and Python 3

Sometimes the error occurs when you have both Python 2 and Python 3 running on the same computer, all you have to do is to run the code bellow to solve the conflict and as a result the error will be solved

                                                                       #
import sys
for i, p in enumerate(sys.path):
    if "python27" in p.lower() or "python2.7" in p.lower(): sys.path.pop(i)
import enum
                                                                       #

I hope this was enough to solve your issue, if it did consider donating to our Kofi account, yuo can use the red button at the top of this page.

Summing-up

Here we are at the end of the road, at the end of this article, if you solved this error congrats, this was a confusing error for me the first time I encountered it.

Make sure to keep coding and keep learning, Python is my favourite programming language, it just needs some patience, cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/