This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: platform.linux_distribution() under Ubuntu returns ('debian', 'squeeze/sid', '')
Type: behavior Stage: needs patch
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: barry, christian.heimes, dmalcolm, doko, draghuram, eric.araujo, ezio.melotti, hodgestar, jaywink, lemburg, pitrou
Priority: normal Keywords: patch

Created on 2010-08-04 17:47 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

File name Uploaded Description Edit
use-lsb-release-first.diff hodgestar, 2010-08-04 18:06 Patch to check /etc/lsb-release first (against trunk r83728) review
Messages (14)
msg112839 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-04 17:47
At least on one of the buildbots:

Re-running test 'test_ssl' in verbose mode
test_ssl: testing with 'OpenSSL 0.9.8o 01 Jun 2010' (0, 9, 8, 15, 15)
          under Linux ('debian', 'squeeze/sid', '')

at the bottom of

Someone on IRC pointed out that on their machine, the system Python returned ('Ubuntu', '10.04', 'lucid').
msg112841 - (view) Author: Simon Cross (hodgestar) Date: 2010-08-04 17:49
I can confirm that I see the ('debian', 'squeeze/sid', '') on py3k and trunk but that the Python 2.6 under Ubuntu reports ('Ubuntu', '10.04', 'lucid').
msg112844 - (view) Author: Simon Cross (hodgestar) Date: 2010-08-04 17:51
I think the problem might be that linux_distribution() reads /etc/debian_version first. The contents of the relevant files in /etc look like:

$ cat /etc/debian_version 

$ cat /etc/lsb-release 
msg112847 - (view) Author: Simon Cross (hodgestar) Date: 2010-08-04 18:06
Patch attached to check /etc/lsb-release before checking other files. Taken from Ubuntu Python 2.6 copy of Applies against trunk (r83728) with a small offset against py3k (r83728).
msg112848 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-04 18:13
FWIW, the output is a bit different here before the patch:
$ ./python -c "import platform; print(platform.linux_distribution())"
('Mandriva Linux', '2010.1', 'Official')

and after the patch:
$ ./python -c "import platform; print(platform.linux_distribution())"
('MandrivaLinux', '2010.1', 'Henry_Farman')

but I would say it's because Mandriva has inconsistent contents in their respective /etc/mandriva_release and /etc/lsb-release files.

The patch itself is a bit imperfect and will need reworking (_u_distname, _u_version and _u_id should be initialized to '' rather than catching UnboundLocalError; remove ubuntu-specific comments).
msg112850 - (view) Author: Simon Cross (hodgestar) Date: 2010-08-04 18:18
I think the intended means of accessing this information is via the lsb_release command ( That said, I don't know if the file format will change drastically unless someone re-implements lsb_release.
msg112853 - (view) Author: Raghuram Devarakonda (draghuram) (Python triager) Date: 2010-08-04 18:31
Please check issue1322 for past discussion on similar topic (usability of lsb_release in
msg112958 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2010-08-05 08:29
I think we'll start to use the lsb_release command if available and as suggested in issue1322.

Note that if you test the API, make sure that you use a Python build from sources available on - the Debian and Ubuntu packagers tend to patch Python in their distributions (just like RedHat and others do) and we don't really want to hunt down bugs/problems that are not relevant to our code base.
msg113038 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2010-08-05 20:18
IMO using lsb_release is not an option, because it can take some time to complete. So maybe it's better for the Ubuntu change to guard the check with the existance of /etc/debian_version.

Please could you attach a Mandriva lsb-release file?
msg113316 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-08-08 20:37
> Please could you attach a Mandriva lsb-release file?

$ cat /etc/lsb-release
DISTRIB_DESCRIPTION="Mandriva Linux 2010.1"

$ cat /etc/mandriva-release 
Mandriva Linux release 2010.1 (Official) for x86_64
msg156292 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-03-18 23:32
Debian and Ubuntu use this patch:
msg172498 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2012-10-09 17:32

is the next step, with the advantage of the definition of the file format for /etc/os-release.
msg224549 - (view) Author: Jason Robinson (jaywink) * Date: 2014-08-02 10:57
platform.linux_distribution is being deprecated in 3.5 and removed in 3.6 as stated in comment in issue #1322

I'm guessing this issue should be closed when that patch is merged in?
msg243091 - (view) Author: Marc-Andre Lemburg (lemburg) * (Python committer) Date: 2015-05-13 14:20
See issue1322
Date User Action Args
2022-04-11 14:57:04adminsetgithub: 53723
2015-05-13 14:20:47lemburgsetstatus: open -> closed
resolution: wont fix
messages: + msg243091
2014-08-02 10:57:26jaywinksetnosy: + ezio.melotti, jaywink
messages: + msg224549
2012-10-09 17:32:20dokosetmessages: + msg172498
2012-10-09 16:18:35christian.heimessetnosy: + christian.heimes
stage: needs patch

versions: + Python 3.4
2012-03-18 23:32:51eric.araujosetmessages: + msg156292
versions: + Python 3.3, - Python 3.1
2010-08-08 20:37:09pitrousetmessages: + msg113316
2010-08-05 21:38:23eric.araujosetnosy: + eric.araujo
2010-08-05 20:18:03dokosetmessages: + msg113038
2010-08-05 08:29:30lemburgsetmessages: + msg112958
2010-08-04 23:45:40pitrousetnosy: + dmalcolm
2010-08-04 18:31:30draghuramsetnosy: + draghuram
messages: + msg112853
2010-08-04 18:18:33hodgestarsetmessages: + msg112850
2010-08-04 18:13:01pitrousetmessages: + msg112848
2010-08-04 18:06:09hodgestarsetfiles: + use-lsb-release-first.diff
keywords: + patch
messages: + msg112847
2010-08-04 17:51:34hodgestarsetmessages: + msg112844
2010-08-04 17:49:25hodgestarsetmessages: + msg112841
2010-08-04 17:47:48pitroucreate