Home > Backend Development > Python Tutorial > 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\'?\'

Linda Hamilton
Release: 2024-11-04 14:45:52
Original
831 people have browsed it

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'
Copy after login

Problem Analysis

Curious as to why this error occurs, we examine the code in question:

<code class="python">class RegexFlag(enum.IntFlag):</code>
Copy after login

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>
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template