@@ -3,27 +3,28 @@ title: How to set up an environment
33---
44
55In 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
77ecosystem. An environment is a workspace into which you can install Python
88libraries, separate from what is being used by your operating system.
99
1010The 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
2930python -m venv science
@@ -41,9 +42,9 @@ You are now ready to install Scientific Python packages using `pip`! For example
4142pip 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
4546environments, 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
4950pip install -r < path/to/requirements.txt>
@@ -55,18 +56,18 @@ Remember to re-activate your environment every time you open a new terminal, usi
5556source 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
6364With conda, we can create a new environment named science (-n is the same as passing --name):
6465
6566``` shell
6667conda create -n science
6768```
6869
69- Start using your environment by activating it:
70+ Start using your environment by activating it:
7071
7172``` shell
7273conda activate science
@@ -79,9 +80,9 @@ For example:
7980conda 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.
8384The 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
8788conda env create -f < path/to/environment.yml>
@@ -93,18 +94,18 @@ Remember to re-activate your environment every time you open a new terminal:
9394conda 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
101102With mamba, like conda, we can create a new environment named science (-n is the same as passing --name):
102103
103104``` shell
104105mamba create -n science
105106```
106107
107- Start using your environment by activating it:
108+ Start using your environment by activating it:
108109
109110``` shell
110111mamba activate science
@@ -117,7 +118,7 @@ For example:
117118mamba 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
123124mamba create -f < /path/to/environment.yml>
@@ -129,19 +130,19 @@ Remember to re-activate your environment every time you open a new terminal:
129130mamba 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
141142uv venv
142143```
143144
144- Start using your environment by activating it:
145+ Start using your environment by activating it:
145146
146147``` shell
147148source .venv/bin/activate
@@ -154,7 +155,7 @@ For example:
154155uv 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
160161uv pip install -f < /path/to/requirements.txt>
@@ -166,15 +167,15 @@ Remember to re-activate your environment time you open a new terminal:
166167source < 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
180181You are now ready to install Scientific Python packages as dependencies in this project!
@@ -184,34 +185,28 @@ From the science directory, execute:
184185pixi 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
190191pixi 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
194195the 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