You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Learn how to set up and use Anaconda with Python in your pipeline. Anaconda is a Python distribution for data science and machine learning.
15
+
Set up and use Anaconda with Python in your pipeline. Anaconda is a Python distribution for data science and machine learning.
16
+
17
+
## Prerequisites
18
+
19
+
Python is preinstalled on [Microsoft-hosted agents](../agents/hosted.md) for Linux, macOS, and Windows. You don't have to set up anything more to build Python projects. To see which Python versions are preinstalled, see [Software](../agents/hosted.md#software).
20
+
21
+
|**Product**|**Requirements**|
22
+
|---|---|
23
+
| **Azure DevOps** | - An [Azure DevOps project](../../organizations/projects/create-project.md).<br> - An ability to run pipelines on Microsoft-hosted agents. You can either purchase a [parallel job](../licensing/concurrent-jobs.md) or you can request a free tier. <br> - Basic knowledge of YAML and Azure Pipelines. For more information, see [Create your first pipeline](../create-first-pipeline.md). <br> - **Permissions:**<br> - To create a pipeline: you must be in the **Contributors** group and the group needs to have *Create build pipeline* permission set to Allow. Members of the [Project Administrators group](../../organizations/security/permissions.md) can manage pipelines. <br> - To create service connections: You must have the *Administrator* or *Creator* role for [service connections](../library/add-resource-protection.md).
24
+
|**GitHub**| - A [GitHub](https://github.com) account. <br> - A [GitHub service connection](../library/service-endpoints.md) to authorize Azure Pipelines.|
16
25
17
26
## Get started
18
27
@@ -28,18 +37,18 @@ Follow these instructions to set up a pipeline for a sample Python app with Anac
28
37
29
38
1. When the list of repositories appears, select your Anaconda sample repository.
30
39
31
-
1. Azure Pipelines will analyze the code in your repository and detect an existing `azure-pipelines.yml` file.
40
+
1. Azure Pipelines analyzes the code in your repository and detects an existing `azure-pipelines.yml` file.
32
41
33
42
1. Select **Run**.
34
43
35
44
1. A new run is started. Wait for the run to finish.
36
45
37
46
> [!TIP]
38
-
> To make changes to the YAML file as described in this topic, select the pipeline in the **Pipelines** page, and then **Edit** the `azure-pipelines.yml` file.
47
+
> To make changes to the YAML file as described in this article, select the pipeline in the **Pipelines** page, and then **Edit** the `azure-pipelines.yml` file.
39
48
40
49
## Add conda to your system path
41
50
42
-
On [hosted agents](../agents/hosted.md), 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.
51
+
On [hosted agents](../agents/hosted.md), conda isn't included in `PATH` by default to prevent its Python version from conflicting with other installed versions. Use the `task.prependpath` agent command to make conda available to all later steps.
43
52
44
53
# [Ubuntu](#tab/ubuntu)
45
54
@@ -56,8 +65,8 @@ Use the `macOS-latest` agent with Anaconda.
56
65
- bash: echo "##vso[task.prependpath]$CONDA/bin"
57
66
displayName: Add conda to PATH
58
67
59
-
# On Hosted macOS, the agent user doesn't have ownership of Miniconda's installation directory/
60
-
# We need to take ownership if we want to update conda or install packages globally
68
+
# On hosted macOS, the agent user doesn't own Miniconda's installation directory.
69
+
# Take ownership if you want to update conda or install packages globally.
61
70
- bash: sudo chown -R $USER $CONDA
62
71
displayName: Take ownership of conda installation
63
72
```
@@ -75,7 +84,7 @@ Use the `macOS-latest` agent with Anaconda.
75
84
76
85
### From command-line arguments
77
86
78
-
The `conda create` command will create an environment with the arguments you pass it.
87
+
The `conda create` command creates an environment with the arguments you pass.
79
88
80
89
# [Ubuntu](#tab/ubuntu)
81
90
@@ -99,7 +108,7 @@ The `conda create` command will create an environment with the arguments you pas
99
108
```
100
109
101
110
> [!NOTE]
102
-
> To add specific conda channels, you need to add an extra line for conda config:
111
+
> To add specific conda channels, add an extra line for conda config:
103
112
> `conda config --add channels conda-forge`
104
113
105
114
@@ -115,15 +124,10 @@ You can check in an [`environment.yml`](https://conda.io/docs/user-guide/tasks/m
115
124
```
116
125
117
126
> [!NOTE]
118
-
> If you are using a self-hosted agent and don't remove the environment at the end, you'll get an
119
-
> error on the next build since the environment already exists. To resolve, use the `--force`
> If you use a self-hosted agent and don't remove the environment at the end, you get an error on the next build because the environment already exists. To fix this, remove the environment before creating a new one with `conda env remove --name your-env-name`.
121
128
122
129
> [!NOTE]
123
-
> If you are using self-hosted agents that are sharing storage, and running jobs in parallel
124
-
> using the same Anaconda environments, there may be clashes between those environments.
125
-
> To resolve, use the `--name` argument and a unique identifier as the argument value,
126
-
> like a concatenation with the `$(Build.BuildNumber)` build variable.
130
+
> If you use self-hosted agents that share storage and run jobs in parallel using the same Anaconda environments, there can be clashes between those environments. To fix this, use the `--name` argument and a unique identifier as the argument value, like a concatenation with the `$(Build.BuildNumber)` build variable.
127
131
128
132
### Install packages from Anaconda
129
133
@@ -133,7 +137,7 @@ The following YAML installs the `scipy` package in the conda environment named `
@@ -162,14 +166,14 @@ The following YAML installs the `scipy` package in the conda environment named `
162
166
163
167
> [!NOTE]
164
168
> Each build step runs in its own process.
165
-
> When you activate an Anaconda environment, it will edit `PATH` and make other changes to its current process.
166
-
> Therefore, an Anaconda environment must be activated separately for each step.
169
+
> When you activate an Anaconda environment, it edits `PATH` and makes other changes to its current process.
170
+
> So, activate an Anaconda environment separately for each step.
167
171
168
172
# [Ubuntu](#tab/ubuntu)
169
173
170
174
```yaml
171
175
- bash: |
172
-
source activate myEnvironment
176
+
conda activate myEnvironment
173
177
python -m pytest --junitxml=junit/unit-test.xml
174
178
displayName: pytest
175
179
@@ -183,7 +187,7 @@ The following YAML installs the `scipy` package in the conda environment named `
183
187
184
188
```yaml
185
189
- bash: |
186
-
source activate myEnvironment
190
+
conda activate myEnvironment
187
191
pytest --junitxml=junit/unit-test.xml
188
192
displayName: pytest
189
193
@@ -209,18 +213,19 @@ The following YAML installs the `scipy` package in the conda environment named `
209
213
210
214
---
211
215
212
-
## FAQs
216
+
217
+
## FAQ
213
218
214
219
### Why am I getting a "Permission denied" error?
215
-
On Hosted macOS, the agent user does not have ownership of the directory where Miniconda is installed.
216
-
For a fix, see the "Hosted macOS" tab under [Add conda to your system path](#add-conda-to-your-system-path).
220
+
On hosted macOS, the agent user doesn't own the directory where Miniconda is installed.
221
+
To fix this issue, go to the "Hosted macOS" tab under [Add conda to your system path](#add-conda-to-your-system-path).
217
222
218
223
### Why does my build stop responding on a `conda create` or `conda install` step?
219
-
If you forget to pass `--yes`, conda will stop and wait for user interaction.
224
+
If you don't pass `--yes`, conda stops and waits for user input.
220
225
221
226
### Why is my script on Windows stopping after it activates the environment?
222
227
On Windows, `activate` is a Batch script. You must use the [`call`](/windows-server/administration/windows-commands/call) command to resume running your script after activating.
223
228
See examples of using `call` [in a pipeline](#run-pipeline-steps-in-an-anaconda-environment).
224
229
225
230
### How can I run my tests with multiple versions of Python?
226
-
See [Build Python apps in Azure Pipelines](./python.md).
231
+
Go to [Build Python apps in Azure Pipelines](./python.md).
0 commit comments