@@ -3,27 +3,28 @@ title: How to set up an environment
3
3
---
4
4
5
5
In this guide we summarize some key commands to set up an environment
6
- with different tools that you might encounter in the scientific python
6
+ with different tools that you might encounter in the scientific python
7
7
ecosystem. An environment is a workspace into which you can install Python
8
8
libraries, separate from what is being used by your operating system.
9
9
10
10
The environment managers that are covered in this how-to guide include:
11
+
11
12
- venv
12
13
- conda
13
14
- mamba
14
15
- uv
15
16
- pixi
16
17
17
- In each of these examples we'll create a new virtual environment related to our
18
- project called ` science ` (you can use whichever name you prefer!). We'll activate
19
- the environment, install some dependencies, and see
20
- an example of installing dependencies from an existing file. You may encounter
21
- files like ` requirements.txt ` , ` environment.yml ` or ` pyproject.toml ` that specify
22
- needed dependencies for a project.
18
+ In each of these examples we'll create a new virtual environment related to our
19
+ project called ` science ` (you can use whichever name you prefer!). We'll activate
20
+ the environment, install some dependencies, and see
21
+ an example of installing dependencies from an existing file. You may encounter
22
+ files like ` requirements.txt ` , ` environment.yml ` or ` pyproject.toml ` that specify
23
+ needed dependencies for a project.
23
24
24
25
### Set up a virtual environment with venv
25
26
26
- With venv to create environment associated with a project folder called ` science ` .
27
+ With venv to create environment associated with a project folder called ` science ` .
27
28
28
29
``` shell
29
30
python -m venv science
@@ -41,9 +42,9 @@ You are now ready to install Scientific Python packages using `pip`! For example
41
42
pip install ipython numpy scipy
42
43
```
43
44
44
- Often you'll interact with projects that have a specific list of dependencies (for development
45
+ Often you'll interact with projects that have a specific list of dependencies (for development
45
46
environments, testing environments, or the project itself). You can install the list of dependencies
46
- with pip in your venv using:
47
+ with pip in your venv using:
47
48
48
49
``` shell
49
50
pip install -r < path/to/requirements.txt>
@@ -55,18 +56,18 @@ Remember to re-activate your environment every time you open a new terminal, usi
55
56
source science/bin/activate
56
57
```
57
58
58
- You can find more information on using venv for packaging
59
+ You can find more information on using venv for packaging
59
60
[ here] ( https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/ ) .
60
61
61
- ### Set up an environment using conda
62
+ ### Set up an environment using conda
62
63
63
64
With conda, we can create a new environment named science (-n is the same as passing --name):
64
65
65
66
``` shell
66
67
conda create -n science
67
68
```
68
69
69
- Start using your environment by activating it:
70
+ Start using your environment by activating it:
70
71
71
72
``` shell
72
73
conda activate science
@@ -79,9 +80,9 @@ For example:
79
80
conda install ipython numpy scipy
80
81
```
81
82
82
- Some projects distribute environment files with listed dependencies with an ` environment.yml ` file.
83
+ Some projects distribute environment files with listed dependencies with an ` environment.yml ` file.
83
84
The first line of this file sets the environment's name. To
84
- create an environment and install the dependencies with this file, use:
85
+ create an environment and install the dependencies with this file, use:
85
86
86
87
``` shell
87
88
conda env create -f < path/to/environment.yml>
@@ -93,18 +94,18 @@ Remember to re-activate your environment every time you open a new terminal:
93
94
conda activate science
94
95
```
95
96
96
- You can find more information on using conda for environments
97
+ You can find more information on using conda for environments
97
98
[ here] ( https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html ) .
98
99
99
- ### Set up an environment using mamba
100
+ ### Set up an environment using mamba
100
101
101
102
With mamba, like conda, we can create a new environment named science (-n is the same as passing --name):
102
103
103
104
``` shell
104
105
mamba create -n science
105
106
```
106
107
107
- Start using your environment by activating it:
108
+ Start using your environment by activating it:
108
109
109
110
``` shell
110
111
mamba activate science
@@ -117,7 +118,7 @@ For example:
117
118
mamba install ipython numpy scipy
118
119
```
119
120
120
- To install a specific environment from a ` .yml ` file, use:
121
+ To install a specific environment from a ` .yml ` file, use:
121
122
122
123
``` shell
123
124
mamba create -f < /path/to/environment.yml>
@@ -129,19 +130,19 @@ Remember to re-activate your environment every time you open a new terminal:
129
130
mamba activate science
130
131
```
131
132
132
- You can find more information on using mamba in the
133
+ You can find more information on using mamba in the
133
134
[ mamba user guide] ( https://mamba.readthedocs.io/en/latest/user_guide/mamba.html ) .
134
135
135
- ### Set up a virtual environment using uv
136
+ ### Set up a virtual environment using uv
136
137
137
- To create a new environment using uv in a project folder called ` science ` ,
138
- navigate to that folder and execute:
138
+ To create a new environment using uv in a project folder called ` science ` ,
139
+ navigate to that folder and execute:
139
140
140
141
``` shell
141
142
uv venv
142
143
```
143
144
144
- Start using your environment by activating it:
145
+ Start using your environment by activating it:
145
146
146
147
``` shell
147
148
source .venv/bin/activate
@@ -154,7 +155,7 @@ For example:
154
155
uv pip install ipython numpy scipy
155
156
```
156
157
157
- To install dependencies from a requirements file, use:
158
+ To install dependencies from a requirements file, use:
158
159
159
160
``` shell
160
161
uv pip install -f < /path/to/requirements.txt>
@@ -166,15 +167,15 @@ Remember to re-activate your environment time you open a new terminal:
166
167
source < path/to/science/> .venv/bin/activate
167
168
```
168
169
169
- You can find more information on using uv for environments
170
+ You can find more information on using uv for environments
170
171
[ here] ( https://docs.astral.sh/uv/pip/environments/#creating-a-virtual-environment ) .
171
172
172
- ### Set up a virtual environment using pixi
173
+ ### Set up a virtual environment using pixi
173
174
174
- To initialize a new project with pixi in our project called ` science ` , execute:
175
+ To initialize a new project with pixi in our project called ` science ` , execute:
175
176
176
177
``` shell
177
- pixi init
178
+ pixi init
178
179
```
179
180
180
181
You are now ready to install Scientific Python packages as dependencies in this project!
@@ -184,34 +185,28 @@ From the science directory, execute:
184
185
pixi add ipython numpy scipy
185
186
```
186
187
187
- To install dependencies from a file like ` environment.yml ` , use:
188
+ To install dependencies from a file like ` environment.yml ` , use:
188
189
189
190
``` shell
190
191
pixi init --import < path/to/environment.yml>
191
192
```
192
193
193
- Remember to re-activate your environment when you re-open a terminal. Navigate to
194
+ Remember to re-activate your environment when you re-open a terminal. Navigate to
194
195
the science folder, and execute:
195
196
196
197
``` shell
197
- pixi shell
198
+ pixi shell
198
199
```
199
200
200
- This will drop you into the default environment for the pixi project, with all
201
- dependencies in that environment accessible to you in that shell.
201
+ This will drop you into the default environment for the pixi project, with all
202
+ dependencies in that environment accessible to you in that shell.
202
203
203
- A pixi project may have multiple environments defined in the ` pixi.toml ` file. To
204
- load a specific environment:
204
+ A pixi project may have multiple environments defined in the ` pixi.toml ` file. To
205
+ load a specific environment:
205
206
206
207
``` shell
207
- pixi shell --environment=< envname>
208
+ pixi shell --environment=< envname>
208
209
```
209
210
210
- You can find more information on using pixi
211
+ You can find more information on using pixi
211
212
[ here] ( https://prefix.dev/docs/pixi/basic_usage ) .
212
-
213
-
214
-
215
-
216
-
217
-
0 commit comments