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
:
JavaScript
x
5
1
>>> import sys
2
>>> import os
3
>>> sys.executable
4
'/usr/bin/python'
5
Then, for Windows, the drive letter will be the first part of splitdrive:
JavaScript
1
3
1
>>> os.path.splitdrive(sys.executable)
2
('', '/usr/bin/python')
3