For Linux this would give me /
, for Windows on the C drive that would give me C:\
. Note that python is not necessarily installed on the C drive on windows.
Advertisement
Answer
You can get the path to the Python executable using sys.executable
:
>>> import sys >>> import os >>> sys.executable '/usr/bin/python'
Then, for Windows, the drive letter will be the first part of splitdrive:
>>> os.path.splitdrive(sys.executable) ('', '/usr/bin/python')