【发布时间】:2017-08-24 18:52:40
【问题描述】:
我刚刚为 MacOS X 安装了 Python 3.6.1
当我尝试运行控制台(或使用 Python3 运行任何东西)时,会抛出此错误:
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'
类 IntFlag 存在于 enum.py 中。那么,为什么会抛出 AttributeError 呢?
【问题讨论】:
-
你的工作目录中是否有文件名
enum.py? -
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6 在 $PATH 中
-
...这不是我问的。我问*您的工作目录中是否有一个名为
enum.py的文件 -
其实是这样。 “确保在你的 shell 配置文件中没有任何地方,PYTHONPATH 设置为指向你的 Python 2.7 安装。”这听起来很可能是造成这种情况的原因。
-
尝试使用
-I选项运行解释器以忽略站点包和环境变量和/或使用-v查看有关导入的详细消息
标签: python python-3.x enums python-3.6 attributeerror