How to install packages from pip without using the cache folder

The pip package installer for Python works by downloading packages using the internet and manages the installation process of the package.

After installing the package, pip will keep a copy of the installed package under the cache folder, which is created when you install Python and pip on your system.

The next time you install the same package, pip will check the cache folder and use it to install the package, so no download from the internet is required.

If you want to disable pip’s cache, you can use the --no-cache-dir option when running the pip install command.

Here’s an example:

pip install numpy --no-cache-dir

# For pip 3:
pip3 install numpy --no-cache-dir

Why would you want to disable the cache? There are many valid reasons you might want to disable the pip’s cache:

  1. The cache folder will increase in size as you download and install packages. You might want to skip saving the package after installing it to preserve system storage
  2. If you use docker, the cache folder will increase the docker’s image size
  3. Force pip to do a fresh install because a corrupted cache
  4. Download the latest version of the package, although you should use the --upgrade option if that’s the case.

You can use the --no-cache-dir option if one of the reasons above applies to your circumstance.

You can find the location and size of your pip cache by running the pip cache info command:

pip cache info
#or:
pip3 cache info

Output:

Package index page cache location: /Users/nsebhastian/Library/Caches/pip/http
Package index page cache size: 1243.8 MB
Number of HTTP files: 519
Locally built wheels location: /Users/nsebhastian/Library/Caches/pip/wheels
Locally built wheels size: 865.2 MB
Number of locally built wheels: 13

As you can see, my cache is already 2GB in size! Using the --no-cache-dir option would come in handy to preserve the disk space on my computer.

Please note that you can also use pip to delete cached packages.

I hope this tutorial is helpful. See you in other tutorials! 👋

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.