What is the use of pip's –user option on Windows?

Question:

I’m confused with the --user option of pip on Windows. It seems that on Windows packages will always be installed to my home directory (C:Users{username}...) regardless of the presence of --user, while on Linux packages will be installed to a global location if --user is omitted:

C:>pip3 install pyyaml
Collecting pyyaml
  Using cached https://files.pythonhosted.org/packages/45/19/53c041b8719eaf88ce1cdb51bea1c5a2844433e79c23a2a8aeeaa0e27fd8/PyYAML-5.1.1-cp37-cp37m-win32.whl
Installing collected packages: pyyaml
Successfully installed pyyaml-5.1.1

C:>pip3 show pyyaml
Name: PyYAML
Version: 5.1.1
Summary: YAML parser and emitter for Python
Home-page: https://github.com/yaml/pyyaml
Author: Kirill Simonov
Author-email: [email protected]
License: MIT
Location: c:users{username}appdatalocalprogramspythonpython37-32libsite-packages
Requires:
Required-by:

C:>pip3 uninstall pyyaml
Uninstalling PyYAML-5.1.1:
  Would remove:
    c:users{username}appdatalocalprogramspythonpython37-32libsite-packages_yaml.cp37-win32.pyd
    c:users{username}appdatalocalprogramspythonpython37-32libsite-packagespyyaml-5.1.1.dist-info*
    c:users{username}appdatalocalprogramspythonpython37-32libsite-packagesyaml*
Proceed (y/n)? y
  Successfully uninstalled PyYAML-5.1.1

C:>pip3 install --user pyyaml
Collecting pyyaml
  Using cached https://files.pythonhosted.org/packages/45/19/53c041b8719eaf88ce1cdb51bea1c5a2844433e79c23a2a8aeeaa0e27fd8/PyYAML-5.1.1-cp37-cp37m-win32.whl
Installing collected packages: pyyaml
Successfully installed pyyaml-5.1.1

C:>pip3 show pyyaml
Name: PyYAML
Version: 5.1.1
Summary: YAML parser and emitter for Python
Home-page: https://github.com/yaml/pyyaml
Author: Kirill Simonov
Author-email: [email protected]
License: MIT
Location: c:users{username}appdataroamingpythonpython37site-packages
Requires:
Required-by:

All the commands above were run under a normal user, not Administrator.

So what is the use of pip’s --user option on Windows? Is it necessary to use --user option whenever I install packages?

Asked By: wtz

||

Answers:

If you had been logged in as the Administrator when the package was installed without the --user option, then the package would have been installed in the Python installation’s Lib/site-packages directory and made available to all user accounts. If, instead you had used the --user option, then, as you have seen, the package would be installed “locally” and only be visible to the Administrator’s account.

Answered By: Booboo

It is indeed confusing how the Windows Python installer handles install location with default settings (which you most probably used).

According to the documentation, when you run the installer and just click “Install Now”:

  • You will not need to be an administrator (unless a system update for the C Runtime Library is required or you install the Python Launcher for Windows for all users)
  • Python will be installed into your user directory
  • The Python Launcher for Windows will be installed according to the option at the bottom of the first page.

Now, the option for the Python Launcher is also selected by default. This means, if your user account is in the “Administrator” group (which it typically is), Python (python.exe) will be installed in your %LocalAppData% directory (just as you have observed). However, the installer will still present you with a UAC prompt to confirm you have admin privileges, as it also wants to install the Python Launcher (py.exe). You end up with a local, “just for me” Python installation in your user directory, though for some intangible reason the Launcher is installed “for all users”.

If you really want to have a system-wide Python installation, you need to select “Customize installation” on the first screen of the installer, then click “Next”, and check “Install for all users” — which is not checked otherwise. The install location will then default to your %ProgramFiles% directory, usually C:Program Files.

When you do user-installs with pip, it will put the packages in your %AppData% directory, which is AppDataRoaming in your user profile (as you have also observed). This is so that when you have a “roaming” account on a domain network, your personally installed packages follow you around, no matter from which computer on the network you log in. Obviously, that computer would have to have a system-wide Python installation “for all users” — of the Python interpreter, not the nearly irrelevant Python Launcher. This is where the default behavior, described above, makes absolutely zero sense, as you wouldn’t be able to run the Python interpreter installed locally in some other user’s profile when you log on to their computer.

On top of that, if you actually do use your profile to “roam” the domain network, all those --user packages, which, more likely than not, comprise thousands of files, will slow down the log-in process: every one of those files has to be sync’ed between domain storage and the local computer.

Bottom line: If you want to set this up properly, customize your installation to make sure it’s installed in some directory that is in fact accessible to all users. Personally, I like to put it in C:programsPython, as I can then pip install anything for everyone and don’t even need an elevated prompt — which one would for writing to C:Program Files. Then again, requiring an elevated prompt may be advisable, depending on the circumstances.

Answered By: john-hen
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.