Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

AttributeError with Python Enum

📅 2015-Jul-16 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ enum, error, python ⬩ 📚 Archive


I had code that had worked correctly with Python 2.7 and that used the old enum module. Recently it started throwing this error:

$ ./ 
Traceback (most recent call last):
  File "./", line 146, in <module>
  File "./", line 100, in draw_plot
    if PlotType.Line == plot_type:
  File "/usr/local/lib/python2.7/dist-packages/enum/", line 373, in __getattr__
    raise AttributeError(name)
AttributeError: Line


This error is caused when the enum34 module has been installed alongside the old enum module. enum34 is the backport for Python 2.x of the standard enum in Python 3.4. Many packages have started to use it and so it will be installed implicitly while installing another package. enum34 overrides the old enum files and causes this error.

You could remove enum34 and get rid of this error. But since Python 3.x has already adapted a new enum type, it might be wiser to uninstall the old enum and rewrite your code to use enum34. Its syntax is shown in this example.

Tried with: Python 2.7.6 and Ubuntu 14.04

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧