Python: 'ImportError: No module named enum' beheben

English Deutsch

Problem:

Sie haben Code wie diesen in Python:

enum_import_example.py
from enum import Enum

Aber beim Ausführen erhalten Sie diesen Fehler:

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

Lösung

Das enum-Modul ist nur in Python 3 verfügbar! Sie versuchen, es in Python 2 zu verwenden.

Versuchen Sie, Ihren Code mit Python 3 auszuführen (z.B. python3 myscript.py). Falls dies nicht möglich ist, da Ihr Projekt oder eine Bibliothek nicht mit Python 3 kompatibel ist, können Sie enum34 installieren, welches das enum-Paket für Python 2 bereitstellt:

install_enum34.sh
pip install -U enum34

Check out similar posts by category: Python