如何修复 Python 'ImportError: No module named enum'
问题:
你在 Python 中有类似这样的代码:
enum_import_example.py
from enum import Enum但当你尝试运行它时,你遇到此错误:
enum_no_module_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 中使用它。
尝试使用 Python3 运行你的代码(例如 python3 myscript.py)。如果由于你的项目或库不兼容 Python 3 而不可能,你可以安装 enum34,它为 Python 2 提供 enum 包:
install_enum34.sh
pip install -U enum34Check 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