Python的pip缓存

pip安装时默认会有缓存,存储在C盘占用空间

查看缓存位置

  • win10下默认缓存路径为:C:\Users\用户名\AppData\Local\pip\cache
  • linux下默认缓存路径为:~/.cache/pip

通过Python命令查看

1
2
3
4
from pip.utils.appdirs import user_cache_dir  # before pip v.10
from pip._internal.utils.appdirs import user_cache_dir # since pip v.10
print(user_cache_dir('pip'))
print(user_cache_dir('wheel'))

修改缓存位置

通过命令的方式

1
pip config set global.cache-dir "新的路径"

通过修改配置文件的方式

  • win10配置文件路径: %APPDATA%\pip\pip.ini

  • linux配置文件路径:~/.config/pip/pip.conf

    1
    2
    3
    4
    5
    [global]
    index-url = http://pypi.douban.com/simple/
    extra-index-url = http://mirrors.aliyun.com/pypi/simple/ https://pypi.python.org/simple https://download.pytorch.org/whl/torch_stable.html
    trusted-host = pypi.douban.com mirrors.aliyun.com pypi.python.org download.pytorch.org
    cache-dir = D:\BCache\python-cache

设置某次pip安装没有缓存

1
2
# pip安装时添加--no-cache-dir参数
pip install requests --no-cache-dir