I cannot get lsb_release module to work in python 2.7 or 3 on debian 9. I haven't tried on debian 8 yet but I need it to work on both.

Here's what I tried:

import lsb_release

it returned {} I don't get an import error, I don't know why it doesn't work. Also, when running a script via sudo with user = os.environ['SUDO_USER'] I get a key error, SUDO_USER doesn't exist? What gives?

1 Answer 1


Please don’t ask multiple questions in one.

Regarding your first question, you should use get_distro_information() instead. get_lsb_information() is used internally to load overrides from /etc/lsb-release; get_distro_information() uses that, along with other methods in the class, to provide the appropriate information.

Regarding your second question, if SUDO_USER really isn’t present in the environment exported by sudo (run sudo env to check), that probably means that your sudoers configuration deletes the variable from the environment.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.