Skip to content
Advertisement

A system independent way using python to get the root directory/drive on which python is installed

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

Then, for Windows, the drive letter will be the first part of splitdrive:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement