Azure DevOps hosted agents have many software so that you don't have to install them every time.
However, in case you need to use some python package, you can do:
- Install them via pip install
- Use conda environment and use environment.yaml
The easiest way to install python package is to use pip install.
I can simply use script task to run:
- script: pip install <package> <package> ..
If there are multiple pipelines which require same package again and again, it's better to manage them at once. In this scenario, you can use either requirements.txt for pip install or conda environment.
Hosted agents has conda installed by default, so I just need to run following commands.
- script: conda env create --quiet --file environment.yml displayName: Create Anaconda environment
One caveat is that I need to activate it in every build step.
Each build step runs in its own process. When you activate an Anaconda environment, it will edit PATH and make other changes to its current process. Therefore, an Anaconda environment must be activated separately for each step.
I use it with Azure CLI task but it works same way.
- task: AzureCLI@1 inputs: azureSubscription: '$(my_subscription_connection)' scriptLocation: inlineScript workingDirectory: $(Build.SourcesDirectory) inlineScript: | # Activate conda environment source activate myenvironment export SUBSCRIPTION_ID=$(az account show --query id -o tsv) # Invoke any azure cli command
GitHub: https://github.com/MicrosoftDocs/pipelines-anaconda has more detail information.