Getting UnparsedFlagAccessError when trying to import glog in python -
i trying use glog in python code , when trying import, throws following error:
/usr/local/lib/python2.7/dist-packages/glog.py:171: runtimewarning: trying access flag verbosity before flags parsed. raise exception in future. setlevel(flags.verbosity) file "<stdin>", line 1, in <module> file "/usr/local/lib/python2.7/dist-packages/glog.py", line 171, in <module> setlevel(flags.verbosity) file "/usr/local/lib/python2.7/dist-packages/gflags/flagvalues.py", line 390, in __getattr__ traceback.print_stack() e0602 09:45:07.674463 4695 flagvalues.py:399] trying access flag verbosity before flags parsed. traceback (most recent call last): file "/usr/local/lib/python2.7/dist-packages/gflags/flagvalues.py", line 391, in __getattr__ raise exceptions.unparsedflagaccesserror(error_message) unparsedflagaccesserror: trying access flag verbosity before flags parsed.
my code follows.
import gflags import glog log
i have searched online haven't got information python version of glog. think error has gflags , glog together. can please explain going wrong ?
i have same issue. after checking code, seems kind of bug of glog.
when import glog
intercepted, assumes gflags.gflags
has been initiated, , tries read gflags.gflags.verbosity
, not guaranteed initialized in cases.
for example, following code throw exception:
import gflags import glog import sys if __name__ == "__main__": gflags.flags(sys.argv) # something.
since when import glog
intercepted, reads flags.vebosity
, since glfags.flags(sys.argv)
not executed yet, reading flags
fail.
so have make sure import gflags
intercepted after gflags
being initialized, solution think of putting import glog
in file instead of main py script.
for example, in main script:
import gflags import sys # don't import evolves of 'glog' flags = gflags.flags if __name__ == "__main__": argv = flags(sys.argv) # import modle uses 'glog' import your_other_module your_other_module.do_something()