如何修复 Python ImportError: cannot import name 'enum'
问题:
你的 Python 代码中有类似这样的一行:
enum_import_example.py
from enum import Enum但当你尝试运行它时,你看到此错误消息:
enum_import_error.txt
Traceback (most recent call last):
File "test.py", line 1, in <module>
from enum import Enum
ImportError: No module named enum解决方案
enum 模块仅在 Python 3 中可用,但你正在使用 Python 2!
你可以尝试使用 Python 3 运行你的脚本。如果不可能(因为你的项目或库不兼容 Python 3),你可以安装 enum34 后向移植
install_enum34.sh
pip install -U enum34安装此包后,ImportError 应该消失。
Check out similar posts by category:
Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow