Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to locate 'pip' when using cache #858

Closed
2 of 5 tasks
jb-2020 opened this issue May 3, 2024 · 11 comments
Closed
2 of 5 tasks

Unable to locate 'pip' when using cache #858

jb-2020 opened this issue May 3, 2024 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@jb-2020
Copy link

jb-2020 commented May 3, 2024

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:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • 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

@jb-2020 jb-2020 added bug Something isn't working needs triage labels May 3, 2024
@aparnajyothi-y
Copy link
Contributor

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

@hamirmahal
Copy link

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

@hamirmahal
Copy link

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
Copy link
Author

jb-2020 commented May 6, 2024

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 gowridurgad self-assigned this May 17, 2024
@gowridurgad
Copy link
Contributor

gowridurgad commented May 30, 2024

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
Copy link
Author

jb-2020 commented May 30, 2024

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
Copy link
Contributor

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
Copy link
Contributor

gowridurgad commented Jun 18, 2024

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

1 similar comment
@gowridurgad
Copy link
Contributor

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

@gowridurgad
Copy link
Contributor

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.

@gblikas
Copy link

gblikas commented Oct 15, 2024

@jb-2020 while not exactly your issue, there was a problem I had when using operating systems that preferred the python3, and pip3 standard.

description

I was running in to an issue where my local self-hosted runner was failing to resolve the pip line in the following usage:

      - name: Set up Python
        # if: steps.cache_build.outputs.cache-hit != 'true'
        uses: actions/setup-python@v5
        with:
          python-version: '3.x'
          cache: 'pip'

And, using cache: pip3 doesn't work either, since actions/setup-python@v5 doesn't support caching with versioned pip. This was common in use-cases for those using act, as their images don't support macOS or Windows, e.g. act -P macos-latest=-self-hosted.

solution

I tried using alias to do this, but it seems like actions/setup-python@v5 probably does some which pip check, resulting in erroneous output.

On macOS, the workaround: create (temporary) a symlink:

ln -s $(which pip3) /usr/local/bin/pip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants