actions / setup-python

Set up your GitHub Actions workflow with a specific version of Python
MIT License
1.59k stars 505 forks source link

Unable to locate 'pip' when using cache #858

Open jb-2020 opened 1 month ago

jb-2020 commented 1 month ago

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:

Runner type:

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

aparnajyothi-y commented 1 month ago

Hello @jb-2020, Thank you for creating the issue and we will look into it :)

hamirmahal commented 1 month ago

I think I may have just recreated the issue at https://github.com/hamirmahal/cache-pip-install/actions/runs/8962394394/job/24611209444.

hamirmahal commented 1 month ago
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

jb-2020 commented 1 month ago
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

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?

gowridurgad commented 1 month ago

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!

Screenshot 2024-05-28 at 2 23 06 PM
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
jb-2020 commented 4 weeks ago

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?

gowridurgad commented 3 weeks ago

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.

  1. 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.
  2. 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. Screenshot 2024-06-03 at 12 30 11 PM
gowridurgad commented 1 week ago

Hi @jb-2020, Just a gentle reminder regarding this issue, If you have any updates or need further assistance, Please let us know.