"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Does Python 3.6.1 Throw \"AttributeError: Module \'enum\' Has No Attribute \'IntFlag\'?\"

Why Does Python 3.6.1 Throw \"AttributeError: Module \'enum\' Has No Attribute \'IntFlag\'?\"

Published on 2024-11-10
Browse:370

Why Does Python 3.6.1 Throw \

Why Python 3.6.1 Throws "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:

class RegexFlag(enum.IntFlag):

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:

import enum
print(enum.__file__)

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.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3