Install Python Package On Per User Basis

There may be many instances where 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 can we 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 the touching system area. In other words, we would restrict 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, as shown below:

pip install --user PACKAGE_NAME

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

I hope you found this tip useful.

If you are interested in watching a video about this, check out my recording on my YouTube channel.

Similar Articles