79268198

Date: 2024-12-10 12:21:01
Score: 2
Natty:
Report link

I have a similar problem but on a Linux machine. I'd summarize the problem and solution, which is already raised in the https://github.com/microsoft/azure-pipelines-tasks/issues/19255 GitHub issue.

Basically, the UsePythonVersion@0 expected to work on hosted agent out of the box. In self-hosted agent, you'll need some tinkering. Add the downloaded Python library folder to the LD_LIBRARY_PATH path:

  1. Connect to the VM via SSH, open the ~/.bashrc file and set the library path:
export LD_LIBRARY_PATH=/home/<your_agent_name>/agent/_work/_tool/Python/3.12.8/x64/lib

On Ubuntu machine, the libpython3.12.so.1.0 library file can be found at the /home/<your_agent_name>/agent/_work/_tool/Python/3.12.8/x64/lib path.

  1. Set the native library path before the Azure pipeline task:
variables:
  pythonVersion: '3.12.8'

jobs:
- job:
  pool: <self_hosted_agent>
  steps:
  - script: |
      echo "##vso[task.setvariable variable=LD_LIBRARY_PATH;]:/home/<your_agent_name>/agent/_work/_tool/Python/$(pythonVersion)/x64/lib"
    displayName: Add the Python library path to the Linux native code library path
  - task: UsePythonVersion@0
    inputs:
      versionSpec: $(pythonVersion)
    displayName: Use Python $(pythonVersion) version

Importantly, you need to specify the exact Python version in order to set the proper path.

Reasons:
  • Blacklisted phrase (1): I have a similar problem
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): I have a similar problem
Posted by: Péter Szilvási