2

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?

4 Answers 4

2

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
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0
>>> 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)]'

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.