Python Absl Duplicate Flag Error

Aug 28, 2020
Duplicate Flag Error: The flag is defined twice : First in package and Second in module inside package

When you happened to use absl in google colab, you could easily bump into Duplicate Flag Error especially when you run flags.DEFINE_ twice (or when you want to add new define).

from absl import flagsFLAGS = flags.FLAGS

Add the following code to reset the define.

for name in list(flags.FLAGS):    delattr(flags.FLAGS,name)

The do your define, or add additional define

flags.DEFINE_string('name', None, 'Project name')flags.DEFINE_integer('version', 1, 'Version number')

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.