Why Python 3.6.1 throws AttributeError: module 'enum' has no attribute 'IntFlag'?

前端 未结 17 1114
无人共我
无人共我 2020-11-22 16:34

I just installed Python 3.6.1 for MacOS X

When I attempt to run the Console(or run anything with Python3), this error is thrown:

  AttributeError: mo         


        
17条回答
  •  死守一世寂寞
    2020-11-22 17:08

    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
    

    That solved my problem.

提交回复
热议问题