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

no-cache-dir = false

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 .

Note: We also publish our tutorials on Medium and If you prefer reading in these platforms, you can follow us there to get our newest articles.

You can reach the author via Twitter:

About the author

Ahmed Bouchefra
is a web developer with 5+ years of experience and technical author with an engineering degree on software development. You can hire him with a click on the link above or contact him via his LinkedIn account. He authored technical content for the industry-leading websites such as SitePoint, Smashing, DigitalOcean, RealPython, freeCodeCamp, JScrambler, Pusher, and Auth0. He also co-authored various books about modern web development that you can find from Amazon or Leanpub

Get our Learn Angular 8 in 15 Easy Steps ebook in pdf, epub and mobi formats, plus a new Angular 8 tutorial every 3 days.

comments powered by Disqus Protection Status