Run pipelines with Anaconda environments
Azure DevOps Services
Learn how to set up and use Anaconda with Python in your pipeline. Anaconda is a Python distribution for data science and machine learning.
Follow these instructions to set up a pipeline for a sample Python app with Anaconda environment.
Sign in to your Azure DevOps organization and navigate to your project.
In your project, navigate to the Pipelines page. Then choose the action to create a new pipeline.
Walk through the steps of the wizard by first selecting GitHub as the location of your source code.
You might be redirected to GitHub to sign in. If so, enter your GitHub credentials.
When the list of repositories appears, select your Anaconda sample repository.
Azure Pipelines will analyze the code in your repository and detect an existing
A new run is started. Wait for the run to finish.
To make changes to the YAML file as described in this topic, select the pipeline in the Pipelines page, and then Edit the
Add conda to your system path
On hosted agents, conda is left out of
PATH by default to keep its Python version from conflicting with other installed versions. The
task.prependpath agent command will make it available to all subsequent steps.
- bash: echo "##vso[task.prependpath]$CONDA/bin" displayName: Add conda to PATH
Create an environment
From command-line arguments
conda create command will create an environment with the arguments you pass it.
- bash: conda create --yes --quiet --name myEnvironment displayName: Create Anaconda environment
You can check in an
environment.yml file to your repo that defines the configuration for an Anaconda environment.
- script: conda env create --quiet --file environment.yml displayName: Create Anaconda environment
If you are using a self-hosted agent and don't remove the environment at the end, you'll get an
error on the next build since the environment already exists. To resolve, use the
conda env create --quiet --force --file environment.yml.
Install packages from Anaconda
The following YAML installs the
scipy package in the conda environment named
- bash: | source activate myEnvironment conda install --yes --quiet --name myEnvironment scipy displayName: Install Anaconda packages
Run pipeline steps in an Anaconda environment
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.
- bash: | source activate myEnvironment python -m pytest --junitxml=junit/unit-test.xml displayName: pytest - task: PublishTestResults@2 inputs: testResultsFiles: 'junit/*.xml' condition: succeededOrFailed()
Why am I getting a "Permission denied" error?
On Hosted macOS, the agent user does not have ownership of the directory where Miniconda is installed. For a fix, see the "Hosted macOS" tab under Add conda to your system path.
Why does my build stop responding on a
conda create or
conda install step?
If you forget to pass
--yes, conda will stop and wait for user interaction.
Why is my script on Windows stopping after it activates the environment?
How can I run my tests with multiple versions of Python?
Submit and view feedback for