Reputation:
I heard changing XDG_CACHE_DIR or XDG_DATA_HOME fixes that but I did
export XDG_CACHE_DIR=<new path>
export XDG_DATA_HOME=<new path>
I've also tried
pip cache dir --cache-dir <new path>
and
pip cache --cache-dir <new path>
and
--cache-dir <new path>
and
python --cache-dir <new path>
from https://pip.pypa.io/en/stable/reference/pip/#cmdoption-cache-dir
and when I type
pip cache dir
It's still in the old location. How do I change the directory of pip cache?
Upvotes: 29
Views: 45161
Reputation: 31
To simplify the Simon's answer even further:
pip config --user set global.cache-dir /your/desired/path
The --user
option says that this setting should be stored in the user-scope pip configuration file and the global
prefix instructs that the cache dir should be used for all pip commands. For more info on that check the pip configuration manual page.
Check if it worked with:
pip cache dir
Upvotes: 3
Reputation: 75645
TL;TR;: do not change XDG_CACHE_HOME
globally unless you are sure you really want to do that.
Changing XDG_CACHE_HOME
globally, like some people suggested would not only affect pip
but also other apps as well. You simply do not want to mess that deep, because it's simply not necessary in most of the cases. So what are your alternatives then? You could be using pip
's --cache-dir <dir>
command line option instead:
pip --cache-dir=<dir> ...
Or you could override value of XDG_CACHE_HOME
variable for pip
invocation only:
XDG_CACHE_HOME=<path> pip ...
which also can be made more permanent by i.e. using shell alias
feature:
alias pip="XDG_CACHE_HOME=<path> pip"
BUT, but, but... there is not need to touch XDG_CACHE_HOME
at all, as pip
can have own configuration file, in which you can override all of the defaults to match your needs, including alternative location of cache directory. Moreover, all command line switches have accompanying environment variables that pip
checks at runtime, which looks like the cleanest approach for your tweaks.
In your particular case, --cache-dir
can be provided via PIP_CACHE_DIR
env variable. So you can either set it globally:
export PIP_CACHE_DIR=<path>
or per invocation:
PIP_CACHE_DIR=<path> pip ...
or, you create said pip's configuration file and set it there.
See docs for more information about pip
config file and variables.
Upvotes: 49
Reputation: 391
To simplify the other answer:
# find the config file location under variant "global"
pip config list -v
# create the file and add
[global]
cache-dir=/path/to/dir
# test if it worked
pip config list
pip cache dir
Upvotes: 14