Python PIP local cache

Python PIP local cache

PIP is the Python Package Manager that allows Python developers and users to easily install Python packages published on the pip remote register by other developers .

If you are using the pip manager frequently then you may find this quick tip useful ,where I'll show how you can activate or enable the local cache of pip which is going to boost the download speed of pip packages .

The idea behind the pip cache is simple ,when you install a Python package using pip for the first time ,it gets saved on the cache .If you try to download/install the same version of the package on a second time ,pip will just use the local cached copy instead of retrieving it from the remote register .

Enabling the local cache of pip


Enabling the local cache of pip is fairly simple so let's do it step by step .

First open the pip configuration file located at ~/.pip/pip.conf with your preferred text editor .

vim ~/.pip/pip.con
On Windows %HOME%\pip\pip.ini

The configuration file can be also located in ~/.config/pip/pip.conf or in /etc/pip.conf

There also legacy per user config files for PIP which are located in :
$HOME/.pip/pip.conf on Unix and MAC
%HOME%\pip\pip.ini on Windows .
Or you can even use a custom file and location for PIP config file using the environment variable PIP_CONFIG_FILE
If you are inside a virtualenv ,you can find the config file in $VIRTUAL_ENV/pip.conf on Unix based systems and %VIRTUAL_ENV%\pip.ini on Windows .
You can find more information about the PIP configuration file here

Then copy and add this

[global]
no-cache-dir = false
download-cache=/usr/local/pip/cache

Next create the folder

mkdir -p /usr/local/pip/cache

Then give it write access

chmod -R 755 /usr/local/pip/cache

You can instead use your profile config file ~/.bash_profile

So open ~/.bash_profile .

And add

export PIP_DOWNLOAD_CACHE=$HOME/.pip_download_cache

That is it ! I hope this was helpful for you .



✋If you have any questions about this article, ask them in our GitHub Discussions 👈 community. You can also Gitter

❤️ Like our page and subscribe to our feed for updates!

Find a list of emojis to copy and paste