Change location of pip cache directory


The below commands only need to be run once for the lifetime of your hazel account.

SUMMARY: By default, the pip cache directory is in $HOME, which causes the “pip install …” command to quickly fill up your home space with big files when you are installing python packages. The pip cache directory location needs to be changed.

  1. Begin by making a cache directory in your /share space using the command below. Note, you can provide any path you like, but just make sure it is somewhere in your “/share/$GROUP/$USER/” space. If you decide on a different path, use it here, and in the rest of the steps below.
    mkdir -p /share/$GROUP/$USER/pip/cache
  2. Issue this command below at the command prompt. It will create a file at $HOME/.config/pip/pip.conf, and set the global pip cache-dir in that file to the path of your pip cache directory.
    pip config set global.cache-dir "/share/$GROUP/$USER/pip/cache"
  3. Confirm everything worked properly:
    Issuing the command below should show (with appropriate $GROUP and $USER):
    [global]
    cache-dir = /share/$GROUP/$USER/pip/cache
    cat $HOME/.config/pip/pip.conf
    Issuing the command below should show an empty directory, and should not show any errors in trying to list the directory.
    ls "/share/$GROUP/$USER/pip/cache"
    Issuing command below should return the the same result as the following command: realpath "/share/$GROUP/$USER/pip/cache".
    pip cache dir

Now all your pip cache files will go to /share/$GROUP/$USER/pip/cache. Your home directory should no longer be filled up by additional “pip install…” cache files.

Copyright © 2024 · Office of Information Technology · NC State University · Raleigh, NC 27695 · Accessibility · Privacy · University Policies