Install Python Package On Per User Basis

Many times it may happen that you want to install a Python package, but you do not have permission to do so at system level.

Then how can we create or run our Python application? How to make that package available for use?

This article focuses on solving this problem with a very simple trick.

One solution to this problem could be to install a package in our own space, rather than touching system area. In other words, restricting everything to our login rather than installing it for all the users using the machine?

Let’s see how we can achieve this solution. Usually, we install any Python package using below command:

pip install PACKAGE_NAME

On execution of this command, a package will appear in the site-packages directory under sys.path.

Apart from this, Python also has a per-user installation directory which is located at ~\AppData\Local\Programs\Python\Python310\Lib\site-packages. In order to restrict package installation to this directory, we need to change our command a little bit as shown below,

pip install — —user PACKAGE_NAME

The good thing about using user switch is, all the packages installed using this technique take priority over the packages already installed on the system.

Hope you find this tip useful. Do not forget to check my recoding of this article here.