Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python installed for all users or current user only?

Using Python, How can I programmatically find whether the Python installed in my PC is installed for all users or for current user only?

like image 906
Raghul Ravichandran Avatar asked Jan 30 '17 13:01

Raghul Ravichandran


2 Answers

If you have installed Python for all users, You should install python in this folder:

C:\Python27

Same as image

enter image description here

for more details check this tutorial

like image 167
Jason Jiménez Avatar answered Sep 26 '22 01:09

Jason Jiménez


You could check if the Python executable is located in the user's home directory. The location of the home directory is retrieved by using the os.path.expanduser() method. The location of the Python interpreter is retrieved by using the sys.executable() method.

The following function returns True if the Python interpreter was installed within the user's home directory, and False otherwise. It works under Linux, and should work under macOS and Windows (but I didn't test those).

import sys
import os

def user_python():
    try:
        return sys.executable.startswith(os.path.expanduser("~"))
    except AttributeError:
        return False

The exception is needed because according to the documentation of sys.executable(), it may return None under some circumstances.

EDIT 2018-12-08: it works on Windows 10.

like image 30
Schmuddi Avatar answered Sep 26 '22 01:09

Schmuddi