das-g
das-g

Reputation: 9994

How can I find out what Python distribution I am using from within Python?

I'm using an application (QGIS) that can execute Python and can be extended with plugins written in Python. Depending on the platform, the installer of this application brings along its own Python distribution which it installs alongside the application to be used by the application. On other platforms, the installation doesn't bring Python along and the system Python interpreter is used.

Can I find out from within Python (in the application's interactive Python console or from within a plugin) what Python is being used?

Upvotes: 2

Views: 196

Answers (4)

kuriouscoder
kuriouscoder

Reputation: 5582

>>> import platform
>>> print(platform.python_version())

Upvotes: 0

WeizhongTu
WeizhongTu

Reputation: 6414

>>> import sys
>>> sys.version
'2.7.12 (default, Jun 29 2016, 14:05:02) \n[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)]'

Upvotes: 0

turkus
turkus

Reputation: 4893

version_info from sys module gives you that answer:

import sys

print sys.version_info
sys.version_info(major=2, minor=7, micro=12, releaselevel='final', serial=0)

You can get every value of it by using ie.:

print sys.version_info.major

Upvotes: 2

das-g
das-g

Reputation: 9994

You can retrieve the path of the Python executable in use with sys.executable:

import sys

print(sys.executable)
# e.g.
#     /usr/bin/python2
# for the system Python 2 interpreter on Linux

Upvotes: 1

Related Questions