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

Running a python command task using image ghcr.io/actions/actions-runner:2.322.0 fails with "Error: python: command not found" #3709

Open
stephen-cox-nzx opened this issue Feb 14, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@stephen-cox-nzx
Copy link

Describe the bug
Using the github runner's container image fails if using shell: python.
There is no alias to python in the image.
Manually entering the running container and running:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10

resolves the issue - this should be part of the image build.

To Reproduce
Steps to reproduce the behaviour:

  1. pull the ghcr.io/actions/actions-runner:2.322.0 image
  2. start the container,
  3. configure and start the runner service within the container
  4. create a simple workflow
name: Run On-Prem activity

on:
  workflow_dispatch:


permissions:
  id-token: write
  contents: read
  actions: read

jobs:
  simple_output:
    name: Test Output
    runs-on: [self-hosted]

    steps:              
      - name: Checkout Source
        id: checkout_source
        uses: actions/checkout@v4
      - name: echo hostname (Python)
        id: echo_hostname
        shell: python
        # needs to have run: sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
        run: |
          """output host info """
          import os
          import uuid
          import platform
          def write_step_summary(message: str):
            """
            Write to the step output summary.
            """
            with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8") as fh:
                print(message, file=fh)
            print(message)
          
          hostname = platform.node()
          write_step_summary('# Container Information')
          write_step_summary(f"Executing on *{ hostname }*")
  1. the workflow fails with Error: python: command not found

A clear and concise description of what you expected to happen.
The inline python script should execute if shell: python is specified

Runner Version and Platform

Version of your runner?

OS of the machine running the runner?

  • container image ghcr.io/actions/actions-runner:2.322.0

What's not working?

Please include error messages and screenshots.

Job Log Output

If applicable, include the relevant part of the job / step log output here. All sensitive information should already be masked out, but please double-check before pasting here.

Run """output host info """
  """output host info """
  import os
  import uuid
  import platform
  
  def write_step_summary(message: str):
    """
    Write to the step output summary.
    """
    with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-[8]") as fh:
        print(message, file=fh)
    print(message)
  
  hostname = platform.node()
  write_step_summary('# Container Information')
  write_step_summary(f"Executing on *{ hostname }*")
  Error: python: command not found

Runner and Worker's Diagnostic Logs

[2025-02-13 23:59:26Z INFO HostContext] Well known directory 'Temp': '/home/runner/_work/_temp'
[2025-02-13 23:59:26Z INFO ExecutionContext] Write event payload to /home/runner/_work/_temp/_github_workflow/event.json
[2025-02-13 23:59:26Z INFO HostContext] Well known directory 'Bin': '/home/runner/bin'
[2025-02-13 23:59:26Z INFO HostContext] Well known directory 'Root': '/home/runner'
[2025-02-13 23:59:26Z INFO HostContext] Well known directory 'Work': '/home/runner/_work'
[2025-02-13 23:59:26Z INFO HostContext] Well known directory 'Temp': '/home/runner/_work/_temp'
[2025-02-13 23:59:26Z INFO ExtensionManager] Getting extensions for interface: 'GitHub.Runner.Worker.IFileCommandExtension'
[2025-02-13 23:59:26Z INFO ExtensionManager] Getting extensions for interface: 'GitHub.Runner.Worker.IActionCommandExtension'
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command internal-set-repo-path
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command set-env
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command set-output
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command save-state
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command add-path
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command add-mask
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command add-matcher
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command remove-matcher
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command warning
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command error
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command notice
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command debug
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command group
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command endgroup
[2025-02-13 23:59:26Z INFO ActionCommandManager] Register action command extension for command echo
[2025-02-13 23:59:26Z INFO ScriptHandler] Which2: 'python'
[2025-02-13 23:59:26Z INFO ScriptHandler] python: command not found. Make sure 'python' is installed and its location included in the 'PATH' environment variable.
[2025-02-13 23:59:26Z INFO JobServerQueue] Try to append 1 batches web console lines for record 'd07233d5-e26b-5a1b-079e-a773d0c1bb7a', success rate: 1/1.
[2025-02-13 23:59:26Z ERR  StepsRunner] Caught exception from step: System.IO.FileNotFoundException: python: command not found
File name: 'python'
   at GitHub.Runner.Sdk.WhichUtil.Which(String command, Boolean require, ITraceWriter trace, String prependPath)
   at GitHub.Runner.Worker.Handlers.ScriptHandler.PrintActionDetails(ActionRunStage stage)
   at GitHub.Runner.Worker.Handlers.Handler.PrepareExecution(ActionRunStage stage)
   at GitHub.Runner.Worker.ActionRunner.RunAsync()
   at GitHub.Runner.Worker.StepsRunner.RunStepAsync(IStep step, CancellationToken jobCancellationToken)
[2025-02-13 23:59:26Z INFO JobServerQueue] Try to append 1 batches web console lines for record 'fe32ccd7-b645-517b-f0ee-13c90cb626de', success rate: 1/1.
[2025-02-13 23:59:26Z INFO JobServerQueue] Try to append 1 batches web console lines for record '3e07e684-8013-57c2-1d26-65b8b2529d93', success rate: 1/1.
[2025-02-13 23:59:26Z INFO StepsRunner] Step result: Failed
@stephen-cox-nzx stephen-cox-nzx added the bug Something isn't working label Feb 14, 2025
@noamgreen
Copy link

noamgreen commented Feb 28, 2025

i am not sure this is a bug , its look loke you dont have python install and you need to add this

    steps:
      - uses: actions/checkout@v4
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}

https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-python

@stephen-cox-nzx
Copy link
Author

stephen-cox-nzx commented Mar 2, 2025

Hi:

i am not sure this is a bug , its look loke you dont have python install and you need to add this

As per the github hosted action docs: "GitHub-hosted runners have a tools cache with pre-installed software, which includes Python and PyPy. You don't have to install anything! "

If I understand correctly, an on-prem github action runner using the action container image should behave equivalently to a github-hosted action runner (with certain caveats regarding ephemerality etc.).

The difference / (the bug?) is that python3 is pre-installed in the container image - but is only accessible using python3 as the command to invoke the interpreter. This differs between a github hosted action runner and a self-hosted action runner using the container image.

When you run a step using the python shell option, it fails, as this translates to executing python ${0} (from memory...) where the ${0} is the contents of the "run" element of the step.

There is no symlink from python to python3 however in the container, so you get a command not found exception (as nothing in the container has an executable called "python".

If you manually run (in the container, on the host as root)

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10

This effectively create a symlink from python to python3, and then the step can complete successfully, as there is now a "python" executable in the path.

For reference, this runs on a github-hosted runner:

name: Run github-hosted activity

on:
  workflow_dispatch:

jobs:
  validate_inputs:
    name: Validating Inputs
    runs-on: ubuntu-latest
    steps:              
      - name: Checkout Source
        id: checkout_source
        uses: actions/checkout@v4
      - name: echo hostname (Python)
        id: echo_hostname
        shell: python
        run: |
          """output host info """
          import os
          import uuid
          import platform
          def write_step_summary(message: str):
            """
            Write to the step output summary.
            """
            with open(os.environ["GITHUB_STEP_SUMMARY"], "a", encoding="utf-8") as fh:
                print(message, file=fh)
            print(message)
          
          hostname = platform.node()
          write_step_summary('# Container Information')
          write_step_summary(f"Executing on *{ hostname }*")

@stephen-cox-nzx
Copy link
Author

Is this issue in the wrong repo - should it be in https://github.com/actions/runner-images/issues?

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

2 participants