question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cross-platform command to return pip's cache directory

See original GitHub issue

What’s the problem this feature will solve?

From the command-line, I’d like a cross-platform method to get pip’s cache directory, which by default is different per OS.

There’s currently no supported way to do this.

Describe the solution you’d like

PR https://github.com/pypa/pip/pull/6391 is adding pip cache info to returns the wheels directory, plus some extra info:

$ pip cache info
Cache info:
  Location: /Users/hugo/Library/Caches/pip/wheels
  Packages: 471

So something like pip cache dir could be a simplified version of that:

$ pip cache dir
/Users/hugo/Library/Caches/pip

This would be useful for caching with GitHub Actions CI. Right now, the config needs repeating three times, once per OS, which is rather cumbersome (https://github.com/actions/cache/pull/86):

      - name: Ubuntu cache
        uses: actions/cache@v1
        if: startsWith(matrix.os, 'ubuntu')
        with:
          path: ~/.cache/pip
          key:
            ${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')
            }}
          restore-keys: |
            ${{ matrix.os }}-${{ matrix.python-version }}-

      - name: macOS cache
        uses: actions/cache@v1
        if: startsWith(matrix.os, 'macOS')
        with:
          path: ~/Library/Caches/pip
          key:
            ${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')
            }}
          restore-keys: |
            ${{ matrix.os }}-${{ matrix.python-version }}-

      - name: Windows cache
        uses: actions/cache@v1
        if: startsWith(matrix.os, 'windows')
        with:
          path: ~\AppData\Local\pip\Cache
          key:
            ${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')
            }}
          restore-keys: |
            ${{ matrix.os }}-${{ matrix.python-version }}-

Other people also want a cross-platform method:

Alternative Solutions

  • The wrong way: use pip’s internal API

Use pip’s private, internal API, which has changed in the past and may change in the future:

$ python -c "from pip._internal.locations import USER_CACHE_DIR; print(USER_CACHE_DIR)"
/Users/hugo/Library/Caches/pip
  • Another way: change pip’s cache dir

Provide --cache-dir or set the PIP_CACHE_DIR environment variable to whatever path you like and cache that. Or use --user to install into the user directory, and cache from there.

However, ideally I’d like not to change pip’s behaviour in any way.

We also test on other CIs, and locally, and I’d like pip to use its defaults as much as possible across the board, and have fewer differences across envs.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
hugovkcommented, Apr 20, 2020

Thanks for the comments! I agree.

To start things off, I’ve created PR https://github.com/pypa/pip/pull/8095 for pip cache dir. It’s simpler to implement, and is easier to use for my actual use case: checking the cache dir on a CI.

1reaction
hugovkcommented, Nov 17, 2019

I agree, I’d like to see #6391 land first and don’t wish to delay it.

Just one thing to consider: perhaps rename “Location:” to “Wheels:” in #6391 to avoid doing it later here. But again, bikeshedding/naming also takes time so we can do it here to avoid delaying #6391 😃

And I’ve created https://github.com/pypa/pip/issues/7372 for https://github.com/pypa/pip/pull/6391#issuecomment-554368620.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change directory of pip cache on Linux? - Stack Overflow
You should be using pip 's --cache-dir <dir> command line argument instead or, ... including alternative location of cache directory.
Read more >
PIP Display pip cache directory using the pip cache command
The pip cache dir command can be used to return the directory where PIP will store cached files. AVOID TROUBLE. There are 3...
Read more >
Caching - pip documentation v22.3.1
pip provides an on-by-default caching, designed to reduce the amount of time spent on duplicate downloads and builds.
Read more >
Pip Clear Cache - Linux Hint
The command: $ pip cache dir. The command should return the directory where the pip cache is located. Example output on Windows and...
Read more >
ansible.builtin.pip module – Manages Python library ...
If you are a Red Hat customer, refer to the Ansible Automation Platform Life Cycle page for ... cd into this directory before...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found