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
/
C:\\\\
Here's what you need:
import sys, os def get_sys_exec_root_or_drive(): path = sys.executable while os.path.split(path)[1]: path = os.path.split(path)[0] return path