What is the correct way to use a different version...
# general
p
What is the correct way to use a different version of Python in CI on GitHub self hosted runners? I'm using GitHub actions with pants 2.22.0 and I want to use Python 3.12 which we use locally and in our current polyrepo setup. Trying to use 3.12 fails with
home/runner/_work/_tool/Python/3.12.7/x64/bin/python3.12: error while loading shared libraries: libpython3.12.so.1.0: cannot open shared object file: No such file or directory
I think this is related to https://github.com/actions/setup-python/issues/871 Are there any accepted solutions beyond the workaround in that ticket to do this that people are using? We have the following in
pants.toml
Copy code
[python]
interpreter_constraints = ["==3.12.*"]
pants lint ::
in CI is failing with
Copy code
Error: 2.79 [ERROR] 1 Exception encountered:
Engine traceback:
  in `lint` goal
ProcessExecutionFailure: Process 'Find interpreter for constraints: CPython==3.12.*' failed with exit code 102.
stdout:
stderr:
Could not find a compatible interpreter.
Examined the following working interpreters:
1.) /usr/bin/python3.10 CPython==3.10.12
Skipped the following broken interpreters:
1.) /home/runner/_work/_tool/Python/3.12.7/x64/bin/python3.12:
/home/runner/_work/_tool/Python/3.12.7/x64/bin/python3.12: error while loading shared libraries: libpython3.12.so.1.0: cannot open shared object file: No such file or directory
f
And while it isn't landed yet, you could pin your CI job to topmost specific commit SHA in tha PR.
Hmm seems to be in a different repo. I assume they need to land that PR and then generate new Python binaries?
p
that fix has been sitting for 5 months - I'm not optimistic it's ever getting merged.
f
Also, you are using a self-hosted runner, could you not just setup the various Python versions in your own runner's image?
(va pyenv or something else)
p
Also, you are using a self-hosted runner, could you not just setup the various Python versions in your own runner's image?
I might have to resort to that.
f
that fix has been sitting for 5 months - I'm not optimistic it's ever getting merged.
😞
a
Hi Wayne, I had a similar problem with GitHub hosted runners and the
setup-python
action. Adding the following to my
pants.toml
allowed the required environment variable to propagate through to the pants processes:
Copy code
[subprocess-environment]
env_vars = ["LD_LIBRARY_PATH"]
d
based on the comment - could you try, at the job level, to set
AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache
and/or
RUNNER_TOOL_CACHE=/opt/hostedtoolcache
so that the self-hosted runner matches the hosted runner config?
p
with
Copy code
env:
  AGENT_TOOLSDIRECTORY: /opt/hostedtoolcache
Setup Python fails with
Error: mkdir: cannot create directory '/opt/hostedtoolcache': Permission denied
I can add a previous step to create this and chown it to root, and setup python then succeeds. But I don't understand the potential security concerns having done this.
Copy code
- name: Create directory and set permissions
        run: |
          sudo mkdir -p /opt/hostedtoolcache
          sudo chmod -R 777 /opt/hostedtoolcache