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):File"/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544,in<module>
main()File"/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 530,in main
known_paths = addusersitepackages(known_paths)File"/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 282,in addusersitepackages
user_site = getusersitepackages()File"/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 258,in getusersitepackages
user_base = getuserbase()# this will also set USER_BASE File"/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 248,in getuserbase
USER_BASE = get_config_var('userbase')File"/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 601,in get_config_var
return get_config_vars().get(name)File"/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 580,in get_config_vars
import _osx_support
File"/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_osx_support.py", line 4,in<module>import re
File"/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 142,in<module>classRegexFlag(enum.IntFlag):AttributeError: module 'enum' has no attribute 'IntFlag'
When I attempt to run the Console(or run anything with Python3), this error is thrown:
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):
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module>
main()
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 530, in main
known_paths = addusersitepackages(known_paths)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 282, in addusersitepackages
user_site = getusersitepackages()
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 258, in getusersitepackages
user_base = getuserbase() # this will also set USER_BASE
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 248, in getuserbase
USER_BASE = get_config_var('userbase')
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 601, in get_config_var
return get_config_vars().get(name)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 580, in get_config_vars
import _osx_support
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_osx_support.py", line 4, in <module>
import re
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'
The class IntFlag exists within enum.py. So, why is the AttributeError being thrown?
It’s because your enum is not the standard library enum module. You probably have the package enum34 installed.
One way check if this is the case is to inspect the property enum.__file__
import enum
print(enum.__file__)
# standard library location should be something like
# /usr/local/lib/python3.6/enum.py
Since python 3.6 the enum34 library is no longer compatible with the standard library. The library is also unnecessary, so you can simply uninstall it.
pip uninstall -y enum34
If you need the code to run on python versions both <=3.4 and >3.4, you can try having enum-compat as a requirement. It only installs enum34 for older versions of python without the standard library enum.
For me this error occured after installing of gcloud component app-engine-python in order to integrate into pycharm. Uninstalling the module helped, even if pycharm is now not uploading to app-engine.
If anyone coming here because of getting this error while running a google app engine Python 3.7 standard environment project in PyCharm then all you need to do is
Make sure the configuration to run is for Flask, not Google App Engine configuration.
Then disable Google App Engine support under Preferences >> Languages & Framework >> Google App Engine
The overall goal is that your app should be fully portable and run in any standard Python environment. You write a standard Python app, not an App Engine Python app. As part of this shift, you are no longer required to use proprietary App Engine APIs and services for your app’s core functionality. At this time, App Engine APIs are not available in the Python 3.7 runtime.
I guess when we create a python 3.7 project in PyCharm as a Google app engine project it still tries to do the same way it does for a python2.7 app
Håken Lid’s answer helped solved my problem (thanks!) , in my case present in Python3.7 running Flask in a Docker container (FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7).
In my case, enum34 was being installed by another library (pip install smartsheet-python-sdk).
For those coming with a similar Docker container problem, here is my final Dockerfile (stripped to the relevant lines):
FROM tiangolo/uwsgi-nginx-flask:python3.7-alpine3.7
...
RUN pip install -r requirements.txt
RUN pip uninstall -y enum34
...
AttributeError: module ‘enum’ has no attribute ‘IntFlag’
simply first i run the command:
unset PYTHONPATH
and then run my desired command then got success in that.
回答 9
使用pip install <required-library> --ignore-installed enum34
安装所需的库后,在构建过程中查找警告。我收到这样的错误: Using legacy setup.py install for future, since package 'wheel' is not installed ERROR: pyejabberd 0.2.11 has requirement enum34==1.1.2, but you'll have enum34 1.1.10 which is incompatible.
I did by using pip install <required-library> --ignore-installed enum34
Once your required library is installed, look for warnings during the build.
I got an Error like this: Using legacy setup.py install for future, since package 'wheel' is not installed ERROR: pyejabberd 0.2.11 has requirement enum34==1.1.2, but you'll have enum34 1.1.10 which is incompatible.
To fix this issue now run the command: pip freeze | grep enum34. This will give you the version of the installed enum34. Now uninstall it by pip uninstall enum34 and reinstall the required version as pip install "enum34==1.1.20"
I have Python 2 and Python 3 installed on my computer. For some strange reason I have in the sys.path of Python 3 also a path to the sitepackage library directory of Python2 when the re module is called. If I run Python 3 and import enum and print(enum.__file__) the system does not show this Python 2 path to site-packages. So a very rough and dirty hack is, to directly modify the module in which enum is imported (follow the traceback paths) and insert the following code just before importing enum:
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 was able to fix this by adding enum34 = “==1.1.8” to pyproject.toml.
Apparently enum34 had a feature in v1.1.8 that avoided this error, but
this regressed in v1.1.9+. This is just a workaround though. The
better solution would be for packages to use environment markers so
you don’t have to install enum34 at all unless needed.
Even I had this issue while running python -m grpc_tools.protoc –version
Had to set the PYTHONPATH till site-packages and shutdown all the command prompt windows and it worked. Hope it helps for gRPC users.
Traceback(most recent call last):File"/usr/lib/python2.7/runpy.py", line 174,in _run_module_as_main
"__main__", fname, loader, pkg_name)File"/usr/lib/python2.7/runpy.py", line 72,in _run_code
exec code in run_globals
File"/home/hu-mka/.local/lib/python2.7/site-packages/ipykernel_launcher.py", line 15,in<module>from ipykernel import kernelapp as app
File"/home/hu-mka/.local/lib/python2.7/site-packages/ipykernel/__init__.py", line 2,in<module>from.connect import*File"/home/hu-mka/.local/lib/python2.7/site-packages/ipykernel/connect.py", line 13,in<module>fromIPython.core.profiledir importProfileDirFile"/home/hu-mka/.local/lib/python2.7/site-packages/IPython/__init__.py", line 48,in<module>from.core.application importApplicationFile"/home/hu-mka/.local/lib/python2.7/site-packages/IPython/core/application.py", line 23,in<module>from traitlets.config.application importApplication, catch_config_error
File"/home/hu-mka/.local/lib/python2.7/site-packages/traitlets/__init__.py", line 1,in<module>from.traitlets import*File"/home/hu-mka/.local/lib/python2.7/site-packages/traitlets/traitlets.py", line 49,in<module>import enum
ImportError:No module named enum
I had this problem in ubuntu20.04 in jupyterlab in my virtual env kernel with python3.8 and tensorflow 2.2.0. Error message was
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/hu-mka/.local/lib/python2.7/site-packages/ipykernel_launcher.py", line 15, in <module>
from ipykernel import kernelapp as app
File "/home/hu-mka/.local/lib/python2.7/site-packages/ipykernel/__init__.py", line 2, in <module>
from .connect import *
File "/home/hu-mka/.local/lib/python2.7/site-packages/ipykernel/connect.py", line 13, in <module>
from IPython.core.profiledir import ProfileDir
File "/home/hu-mka/.local/lib/python2.7/site-packages/IPython/__init__.py", line 48, in <module>
from .core.application import Application
File "/home/hu-mka/.local/lib/python2.7/site-packages/IPython/core/application.py", line 23, in <module>
from traitlets.config.application import Application, catch_config_error
File "/home/hu-mka/.local/lib/python2.7/site-packages/traitlets/__init__.py", line 1, in <module>
from .traitlets import *
File "/home/hu-mka/.local/lib/python2.7/site-packages/traitlets/traitlets.py", line 49, in <module>
import enum
ImportError: No module named enum
problem was that in symbolic link in /usr/bin/python was pointing to python2. Solution:
cd /usr/bin/
sudo ln -sf python3 python
Hopefully Python 2 usage will drop off completely soon.
If anyone is having this problem when trying to run Jupyter kernel from a virtualenv, just add correct PYTHONPATH to kernel.json of your virtualenv kernel (Python 3 in example):