actions / runner-images

GitHub Actions runner images
MIT License
9.82k stars 3.01k forks source link

pip and python3 mismatch on macos-14 runners #10385

Closed tstellar closed 2 days ago

tstellar commented 1 month ago

Description

It appears that the default pip binary and default python3 binary on the macos-14 runners use different python installs. So any python modules you install via pip are cannot be found by python3.

Platforms affected

Runner images affected

Image version and build link

Runner Version: 20240728.1

https://github.com/tstellar/llvm-project/actions/runs/10223278047/job/28289331074

Is it regression?

Yes, it was working with 20240722.3

Expected behavior

Python3 should be able to import modules installed via pip.

Actual behavior

pip install pygithub
python3 -c 'import github'

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'github'

Repro steps

You can reproduce the problem with this workflow:

name: Test Python

on:
  push:

permissions:
  contents: read # Default everything to read-only

jobs:
  test-python:
    runs-on: macos-14
    steps:
      - shell: bash
        run: |
          pip install pygithub
          python3 -c 'import github'
prasanjitsahoo commented 1 month ago

Hi @tstellar, We are looking in to it.

prasanjitsahoo commented 1 month ago

Hi @tstellar,

We could see the above behaviour only for ARM64 based images. We will check more on it and keep you posted on our investigation. Currently, you can use the below two solutions to continue with our ARM64 images.

Solution-1: Use setup-python actions

steps:
  - uses: actions/checkout@v4
  - uses: actions/setup-python@v5
    with:
      python-version: '3.12'
  - name: Install PyGithub
    run: |
      pip install pygithub
      python3 -c 'import github'

Solution-2: To install a Python library, we can use a virtual environment

steps:
  - name: Install PyGithub
    run: |
      python3 -m venv .venv
      source .venv/bin/activate
      pip install pygithub
      python3 -c 'import github'
sarathrajsrinivasan commented 4 days ago

Hi @tstellar ,

We have two installations of Python here. One is via Homebrew and the other is via the official Python.org installer.

When we run "pip install pygithub" initially, it invokes the pip installed by the Python.org installer and downloads to the location - "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages"

pip --version 
ARM : pip 24.2 from /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pip (python 3.12)

When we run "python3 -c import github" following it, it considers the pip which is installed by the homebrew now.

python3 -m pip --version
ARM : pip 24.0 from /opt/homebrew/lib/python3.12/site-packages/pip (python 3.12)

Since python3 used above is installed using Homebrew and Homebrew doesn't directly manage installation of pygithub we suggest using the above two options (setup-python actions / using virtual environment) to resolve the same.