Ratha
Ratha

Reputation: 9692

python3.6 and enum module issue in MAC OS

I have 2 python versions 2.7 and 3.6. I set my virtual environment to run on python3

# virtualenv -p python3 venv
# source venv/bin/activate
# pip install -r requirements.txt

When I try to install modules I get following error,

Collecting enum==0.4.6 (from -r requirements.txt (line 12))
  Using cached https://files.pythonhosted.org/packages/0c/4e/1ea357e7783c756bb579333c1e4a026fb331371ee771f616ffedc781e531/enum-0.4.6.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/Users/ratha/projects/test711/ATGWS/venv/lib/python3.6/site-packages/setuptools/__init__.py", line 5, in <module>
        import distutils.core
      File "/Users/ratha/projects/test711/ATGWS/venv/lib/python3.6/distutils/__init__.py", line 4, in <module>
        import imp
      File "/Users/ratha/projects/test711/ATGWS/venv/lib/python3.6/imp.py", line 27, in <module>
        import tokenize
      File "/Users/ratha/projects/test711/ATGWS/venv/lib/python3.6/tokenize.py", line 33, in <module>
        import re
      File "/Users/ratha/projects/test711/ATGWS/venv/lib/python3.6/re.py", line 142, in <module>
        class RegexFlag(enum.IntFlag):
    AttributeError: module 'enum' has no attribute 'IntFlag'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/ct/v0v5ht_n32n6c_33dw1td2fc0000gp/T/pip-install-36x_vm0b/enum/

In my code, I use following import;

from enum import Enum

How can I overcome this issue with python 3 version?

Note : I do not have enum34 module installed

#pip uninstall enum34 :Skipping enum34 as it is not installed.

This answers here didnt solve my issue Why Python 3.6.1 throws AttributeError: module 'enum' has no attribute 'IntFlag'?

Upvotes: 2

Views: 1132

Answers (1)

mjoelnir
mjoelnir

Reputation: 11

I'm working on MacOS with Python3 and Jupyter. I have received a similar error message

Failed to import the site module
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 544, in <module>
    main()
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 530, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site.py", line 282, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/local/Cellar/python/3.6.5/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/python/3.6.5/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/python/3.6.5/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/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/sysconfig.py", line 580, in get_config_vars
    import _osx_support
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/_osx_support.py", line 4, in <module>
    import re
  File "/usr/local/Cellar/python/3.6.5/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'

Note that the call has a different origin. Still, both result in the re.py module causing the AttributeError emerging from enum.py

For me, the following approach solved the issue:

In my kernel.json configuration I explicitly specified the PYTHONPATH pointing to the site-package directory. The revised version looks like this:

{
 "argv": [
  "/usr/local/opt/python/bin/python3.6",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "Python 3",
 "language": "python",
 "env": {
     "PYTHONPATH": "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/"
 }
}

The env part had been missing. After adding the path, the error message disappeared.

Please note, I have used homebrew to install python3 and I'm not using conda or virtualenv.

I hope this may help you :)

Upvotes: 1

Related Questions