Home >Backend Development >Python Tutorial >Why Does Python 3.6.1 Throw \'AttributeError: Module \'enum\' Has No Attribute \'IntFlag\'?\'
After installing Python 3.6.1 for macOS X, an attempt to use the console or run anything with Python3 yields a cryptic error message:
AttributeError: module 'enum' has no attribute 'IntFlag'
Problem Analysis
Curious as to why this error occurs, we examine the code in question:
<code class="python">class RegexFlag(enum.IntFlag):</code>
The class RegexFlag inherits from enum.IntFlag, which is a member of the enum module. However, we encounter the error because Python throws an AttributeError exception, indicating that the module enum lacks the attribute IntFlag.
Solution
Delving into the issue, we discover that the enum module in use may not be the standard library's. The enum34 package, designed for Python versions below 3.5, may be installed alongside the standard library's enum in Python 3.6.1.
Verifying the authenticity of enum can be done by inspecting its file path:
<code class="python">import enum print(enum.__file__)</code>
If enum.__file__ does not point to the standard library location (e.g., /usr/local/lib/python3.6/enum.py), then the enum34 package is likely the cause of the issue.
Resolution
To rectify the situation, uninstall enum34:
pip uninstall -y enum34
Alternatively, if the code needs to run on both Python versions prior to 3.5 and greater than 3.5, consider using the enum-compat package. This package installs enum34 only for older Python versions that lack the standard library's enum module.
The above is the detailed content of Why Does Python 3.6.1 Throw \'AttributeError: Module \'enum\' Has No Attribute \'IntFlag\'?\'. For more information, please follow other related articles on the PHP Chinese website!