1

I've been trying to figure out how to tell the user what distribution the python interpreter is in, without having to specifically code in a check for each distribution. For instance, I know that I could check whether the interpreter is Anaconda by using this code:

from os.path import (exists, join)
from sys import prefix
if exists(join(prefix, 'conda-meta', 'history')):
    print('Anaconda Distribution')
else:
    print('Unknown Distribution')

However, this means I would have to write a check for every known distribution and update my code whenever a new distribution appears. I noticed that Python's interpreter will automatically tell you this information: (On my Anaconda machine)

python
Python 3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

(And on my default Python computer)

python
Python 3.8.3 (default, Jul  2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

So obviously the Python interpreter knows what distribution it is in. Is there any function in python that will give you that information? e.g. (some sys-like module).distribution

Thanks!

EDIT: sys.version only gives me the version, not the :: Anaconda, Inc. when I tested it.

  • 1
    https://stackoverflow.com/questions/1093322/how-do-i-check-what-version-of-python-is-running-my-script – unil Jul 13 '20 at 16:46
  • `sys.version` does not give me the distribution. On both machines it gives `3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)]` – Mr. Brainfart Jul 13 '20 at 16:50

0 Answers0