11

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

3
  • I'm a Linux user, but couldn't you go in your PATH variable and see if it's added for just a user, or globally? First thought. Haven't used Windows since.. 2011 though. Commented Jan 30, 2017 at 13:07
  • For all user python will be installed in program files, for the current user, it will be in appdata. Commented Nov 20, 2022 at 13:10
  • The installer for python 3 is kind of a nightmare. Even the 'all users' install only puts an uninstall entry in the registry of the current user. Commented Nov 7, 2024 at 15:39

2 Answers 2

8

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

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.