Unable to locate 'pip' when using cache
Description:
We're on GHES and using self-hosted runners. We're using this action successfully by populating the RUNNER_TOOL_CACHE with our version sourced from a github-proxy of actions/python-versions.:
Run actions/setup-python@v4
Installed versions
Successfully set up CPython (3.12.0)
Unfortunately, after attempting to use the pip cache we receive the following error:
Unable to locate executable file: pip.
Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable.
Also check the file mode to verify the file is executable.
For what its worth, after running setup-python without the cache flag enabled I added a couple steps to the workflow to view the behavior of pip:
Run pip --version
/home/runner/_work/_temp/188bb107-50a4-4b41-a141-38988abcb76d.sh: line 1: pip: command not found
/home/runner/_work/_temp/f10f49fe-29ae-4ebc-b6d2-9f2080f8c6a0.sh:
/home/runner/_work/_tool/Python/3.12.0/x64/bin/pip3: /opt/hostedtoolcache/Python/3.12.0/x64/bin/python3.12: bad interpreter: No such file or directory
I've verified the appropriate environment variable as well: RUNNER_TOOL_CACHE=/home/runner/_work/_tool
Action version:
actions/setup-python@v4 - This is the latest available on our version of GHES.
Platform:
- [x] Ubuntu
- [ ] macOS
- [ ] Windows
Runner type:
- [ ] Hosted
- [x] Self-hosted
Tools version: 3.12.0
Repro steps:
This doesn't appear to have been reported in the past, looking for pointers in the right direction to determine if this is an issue in our runner environment.
Expected behavior: Cache to work as expected
Actual behavior: See above
Hello @jb-2020, Thank you for creating the issue and we will look into it :)
I think I may have just recreated the issue at https://github.com/hamirmahal/cache-pip-install/actions/runs/8962394394/job/24611209444.
name: Run
on: [push]
jobs:
python-program:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
cache: "pip"
python-version: "3.x"
- run: python3 src/main.py
results in
Error: Cache folder path is retrieved for pip but doesn't exist on disk: /home/runner/.cache/pip
name: Run on: [push] jobs: python-program: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: cache: "pip" python-version: "3.x" - run: python3 src/main.pyresults in
Error: Cache folder path is retrieved for pip but doesn't exist on disk: /home/runner/.cache/pip
Thanks for checking it out @hamirmahal worth noting that our error messages are different and in our case it is a fatal error:
Unable to locate executable file: pip.
Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable.
Also check the file mode to verify the file is executable.
Looking at your workflow, I think setup-python did manage to find the executable file?
Hi @jb-2020, I have attempted to reproduce the issue on my end, but was unable to do so. In our test environment, we have used pip cache without any errors, Here's a screenshot for your reference. Could you assist by sharing a link to a simplified version that reproduces the problem? Thank you!
jobs:
test:
runs-on: self-hosted
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
cache: 'pip'
- name: Display Python version
run: python --version
- name: Check pip
run: |
which pip
pip --version
Thanking for checking it out, since we are in an air-gaped environment we are pulling:
python-${PYTHON_VERSION}-linux-22.04-x64.tar.gz from a proxy of https://github.com/actions/python-versions/
Then populating the tools cache with:
mkdir -p ${RUNNER_TOOL_CACHE}/Python/${{ inputs.python-version }}/x64
tar -xzf python-${{ inputs.python-version }}.tar.gz --directory ${RUNNER_TOOL_CACHE}/Python/${{ inputs.python-version }}/x64
touch ${RUNNER_TOOL_CACHE}/Python/${{ inputs.python-version }}/x64.complete
rm -f python-${{ inputs.python-version }}.tar.gz
Which does install correctly, but pip isn't found. Any thoughts on this approach?
Hi @jb-2020 , We have followed the approach mentioned in the above comment and successful install the python and used the pip cache without any errors. Here's a screenshot and workflow file for your reference.
- name: Set up Python
run: |
PYTHON_VERSION=3.9.5
RUNNER_TOOL_CACHE=/home/azureuser/actions-runner/_work/_temp
mkdir -p ${RUNNER_TOOL_CACHE}/Python/${PYTHON_VERSION}/x64
curl -O https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz
tar -xzf Python-${PYTHON_VERSION}.tgz --directory ${RUNNER_TOOL_CACHE}/Python/${PYTHON_VERSION}/x64
touch ${RUNNER_TOOL_CACHE}/Python/${PYTHON_VERSION}/x64.complete
rm -f Python-${PYTHON_VERSION}.tgz
- name: Cache pip packages
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
- name: Verify Python Installation
run: |
python3 --version
Here are a few solutions which might reslove this issue.
- Verify if pip is included in the tar.gz file: Extract the tar.gz file manually and confirm if pip is indeed included. It is typically located in the bin directory.
- Download a different tar.gz file: If pip is not included in the tar.gz file, you might need to download a different Python tar.gz file that includes pip.
Hi @jb-2020, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.
Hi @jb-2020, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.
Hello @jb-2020 Due to inactivity, I'm going to close this issue for now. Please feel free to reopen this issue or create a new one if necessary. Thank you.