Python “pip install –user” Command

Python is a dynamic and popular programming language which provides a lot of different libraries or module. Even python provides a wide module selection there are also a lot of 3rd party libraries provided via the Python Package Index (PyPI). The pip is used to install 3rd party modules from this index. The pip command can install these 3rd party packages for all users or specific users. The “pip install –user” is used to installing a 3rd party package for a specific user. This means this installed package will not be available for other users.

“pip install” Command

By default, the “pip install” command is used to install a package for all users. This means the package will be installed into the system directory like “/usr/local/lib/python3.8” in Linux systems. In order to write this directory, the installation requires root privileges. But if the user does not has any root privileges he can not install a python package into the global package library or system directory.

“pip install –user” Command

What makes the “pip install –user” command very special and useful it can be used by a regular user without any root privilege or running the sudo command to install a python package. Use following pip command to install django package into the user home directory. Actually the –user installs package into the site.USER_SITE path which is defined in python environment variables.

You can list the user site path with the following python command.

$ python3 -m site --user-base

The output will be like below for the Linux distributions like Ubuntu, Debian, Mint, Kali, Fedora, CentOS, etc. But also the /lib/python3.8/site-packages should be added into this path which will be “/home/ismail/.local/lib/python3.8/site-packages/

/home/ismail/.local

We can list pip packages installed for the current user with the ls command like below. The current user is named “ismail”.

$ ls -l /home/ismail/.local/lib/python3.8/site-packages/
Pip User Specific Site Packages

If you are using Windows operating systems the “pip install –user” installs the 3rd party packages into the “C:\Users\Username\AppData\Roaming\Python38\site-packages” path where the Username is the current user home directory and Python38 is the installed python version.

Leave a Comment