Reputation: 9994
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
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
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
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