Skip to content

Commit 3051600

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 3052c7d commit 3051600

File tree

1 file changed

+39
-44
lines changed

1 file changed

+39
-44
lines changed

content/how-tos/how-to-create-environments.md

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,28 @@ title: How to set up an environment
33
---
44

55
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
77
ecosystem. An environment is a workspace into which you can install Python
88
libraries, separate from what is being used by your operating system.
99

1010
The environment managers that are covered in this how-to guide include:
11+
1112
- venv
1213
- conda
1314
- mamba
1415
- uv
1516
- pixi
1617

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.
2324

2425
### Set up a virtual environment with venv
2526

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`.
2728

2829
```shell
2930
python -m venv science
@@ -41,9 +42,9 @@ You are now ready to install Scientific Python packages using `pip`! For example
4142
pip install ipython numpy scipy
4243
```
4344

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
4546
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:
4748

4849
```shell
4950
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
5556
source science/bin/activate
5657
```
5758

58-
You can find more information on using venv for packaging
59+
You can find more information on using venv for packaging
5960
[here](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/).
6061

61-
### Set up an environment using conda
62+
### Set up an environment using conda
6263

6364
With conda, we can create a new environment named science (-n is the same as passing --name):
6465

6566
```shell
6667
conda create -n science
6768
```
6869

69-
Start using your environment by activating it:
70+
Start using your environment by activating it:
7071

7172
```shell
7273
conda activate science
@@ -79,9 +80,9 @@ For example:
7980
conda install ipython numpy scipy
8081
```
8182

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.
8384
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:
8586

8687
```shell
8788
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:
9394
conda activate science
9495
```
9596

96-
You can find more information on using conda for environments
97+
You can find more information on using conda for environments
9798
[here](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html).
9899

99-
### Set up an environment using mamba
100+
### Set up an environment using mamba
100101

101102
With mamba, like conda, we can create a new environment named science (-n is the same as passing --name):
102103

103104
```shell
104105
mamba create -n science
105106
```
106107

107-
Start using your environment by activating it:
108+
Start using your environment by activating it:
108109

109110
```shell
110111
mamba activate science
@@ -117,7 +118,7 @@ For example:
117118
mamba install ipython numpy scipy
118119
```
119120

120-
To install a specific environment from a `.yml` file, use:
121+
To install a specific environment from a `.yml` file, use:
121122

122123
```shell
123124
mamba create -f </path/to/environment.yml>
@@ -129,19 +130,19 @@ Remember to re-activate your environment every time you open a new terminal:
129130
mamba activate science
130131
```
131132

132-
You can find more information on using mamba in the
133+
You can find more information on using mamba in the
133134
[mamba user guide](https://mamba.readthedocs.io/en/latest/user_guide/mamba.html).
134135

135-
### Set up a virtual environment using uv
136+
### Set up a virtual environment using uv
136137

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:
139140

140141
```shell
141142
uv venv
142143
```
143144

144-
Start using your environment by activating it:
145+
Start using your environment by activating it:
145146

146147
```shell
147148
source .venv/bin/activate
@@ -154,7 +155,7 @@ For example:
154155
uv pip install ipython numpy scipy
155156
```
156157

157-
To install dependencies from a requirements file, use:
158+
To install dependencies from a requirements file, use:
158159

159160
```shell
160161
uv pip install -f </path/to/requirements.txt>
@@ -166,15 +167,15 @@ Remember to re-activate your environment time you open a new terminal:
166167
source <path/to/science/>.venv/bin/activate
167168
```
168169

169-
You can find more information on using uv for environments
170+
You can find more information on using uv for environments
170171
[here](https://docs.astral.sh/uv/pip/environments/#creating-a-virtual-environment).
171172

172-
### Set up a virtual environment using pixi
173+
### Set up a virtual environment using pixi
173174

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:
175176

176177
```shell
177-
pixi init
178+
pixi init
178179
```
179180

180181
You are now ready to install Scientific Python packages as dependencies in this project!
@@ -184,34 +185,28 @@ From the science directory, execute:
184185
pixi add ipython numpy scipy
185186
```
186187

187-
To install dependencies from a file like `environment.yml`, use:
188+
To install dependencies from a file like `environment.yml`, use:
188189

189190
```shell
190191
pixi init --import <path/to/environment.yml>
191192
```
192193

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
194195
the science folder, and execute:
195196

196197
```shell
197-
pixi shell
198+
pixi shell
198199
```
199200

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.
202203

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:
205206

206207
```shell
207-
pixi shell --environment=<envname>
208+
pixi shell --environment=<envname>
208209
```
209210

210-
You can find more information on using pixi
211+
You can find more information on using pixi
211212
[here](https://prefix.dev/docs/pixi/basic_usage).
212-
213-
214-
215-
216-
217-

0 commit comments

Comments
 (0)