Use Python Version task

Azure Pipelines

Use this task in a build or release pipeline to select a version of Python to run on an agent, and optionally add it to PATH.




  • A Microsoft-hosted agent with side-by-side versions of Python installed, or a self-hosted agent with Agent.ToolsDirectory configured (see Q&A).

This task will fail if no Python versions are found in Agent.ToolsDirectory. Available Python versions on Microsoft-hosted agents can be found here.


x86 and x64 versions of Python are available on Microsoft-hosted Windows agents, but not on Linux or macOS agents.

YAML snippet

# Use Python Version
# Retrieves the specified version of Python from the tool cache. Optionally add it to PATH.
- task: UsePythonVersion@0
    #versionSpec: '3.x' 
    #addToPath: true 
    #architecture: 'x64' # Options: x86, x64 (this argument applies only on Windows agents)


Argument Description Default
Version spec Version range or exact version of a Python version to use. 3.x
Add to PATH Whether to prepend the retrieved Python version to the PATH environment variable to make it available in subsequent tasks or scripts without using the output variable. true
Advanced - Architecture The target architecture (x86, x64) of the Python interpreter. x64

As of version 0.150 of the task, version spec will also accept pypy2 or pypy3.

If the task completes successfully, the task's output variable will contain the directory of the Python installation:

output variable

Open source

This task is open source on GitHub. Feedback and contributions are welcome.

Q & A

Where can I learn more about tool installers?

For an explanation of tool installers and examples, see Tool installers.

Do I need an agent?

You need at least one agent to run your build or release. Get an agent for Linux, macOS, or Windows.

I can't select a default agent pool and I can't queue my build or release. How do I fix this?

See Agent pools.

How can I configure a self-hosted agent to use this task?

You can run this task on a self-hosted agent with your own Python versions. To run this task on a self-hosted agent, set up Agent.ToolsDirectory by following the instructions here. The tool name to use is "Python."