Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DuplicateFlagError: The flag 'echo' is defined twice. #130

Closed
Rich2006 opened this issue Feb 29, 2020 · 2 comments
Closed

DuplicateFlagError: The flag 'echo' is defined twice. #130

Rich2006 opened this issue Feb 29, 2020 · 2 comments

Comments

@Rich2006
Copy link

I tried to run below code provided in the repository but I get DuplicateFlagError, can you please assist.

from future import absolute_import
from future import division
from future import print_function

import sys

from absl import app
from absl import flags
from absl import logging

FLAGS = flags.FLAGS

flags.DEFINE_string('echo', None, 'Text to echo.')

def main(argv):
del argv # Unused.

print('Running under Python {0[0]}.{0[1]}.{0[2]}'.format(sys.version_info),
file=sys.stderr)
logging.info('echo is %s.', FLAGS.echo)

if name == 'main':
app.run(main)

See error below

DuplicateFlagError Traceback (most recent call last)
in
11 FLAGS = flags.FLAGS
12
---> 13 flags.DEFINE_string('echo', None, 'Text to echo.')
14
15

~\Anaconda3\envs\venv\lib\site-packages\absl\flags_defines.py in DEFINE_string(name, default, help, flag_values, **args)
239 parser = _argument_parser.ArgumentParser()
240 serializer = _argument_parser.ArgumentSerializer()
--> 241 DEFINE(parser, name, default, help, flag_values, serializer, **args)
242
243

~\Anaconda3\envs\venv\lib\site-packages\absl\flags_defines.py in DEFINE(parser, name, default, help, flag_values, serializer, module_name, **args)
80 """
81 DEFINE_flag(_flag.Flag(parser, serializer, name, default, help, **args),
---> 82 flag_values, module_name)
83
84

~\Anaconda3\envs\venv\lib\site-packages\absl\flags_defines.py in DEFINE_flag(flag, flag_values, module_name)
102 # Copying the reference to flag_values prevents pychecker warnings.
103 fv = flag_values
--> 104 fv[flag.name] = flag
105 # Tell flag_values who's defining the flag.
106 if module_name:

~\Anaconda3\envs\venv\lib\site-packages\absl\flags_flagvalues.py in setitem(self, name, flag)
428 # module is simply being imported a subsequent time.
429 return
--> 430 raise _exceptions.DuplicateFlagError.from_flag(name, self)
431 short_name = flag.short_name
432 # If a new flag overrides an old one, we need to cleanup the old flag's

DuplicateFlagError: The flag 'echo' is defined twice. First from C:\Users\lenovo\Anaconda3\envs\venv\lib\site-packages\ipykernel_launcher.py, Second from C:\Users\lenovo\Anaconda3\envs\venv\lib\site-packages\ipykernel_launcher.py. Description from first occurrence: Text to echo.

@yilei
Copy link
Contributor

yilei commented Mar 2, 2020

Are you using IPython? This is likely due to your code being run twice with the same process (thus the flag is defined twice).

This is a similar user report: #36 (comment)

@Rich2006
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants