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
Copy file name to clipboardExpand all lines: conda.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,8 @@
13
13
14
14
## Installing conda, *if you don't have it already*
15
15
16
+
(Note: I encourage using `conda` version no older than 23.10.)
17
+
16
18
1. There are several distributions of `conda` and it can pull packages from many different sources
17
19
called "channels". In this workshop we will use the [conda-forge](https://conda-forge.org) distribution called "miniforge" (or "miniforge3").
18
20
- Go to the conda-forge downloads page:
@@ -41,7 +43,7 @@
41
43
Type:
42
44
43
45
```bash
44
-
conda env create -n bestpractices
46
+
conda create -n bestpractices
45
47
```
46
48
47
49
This will create a new environment named "bestpractices" (`-n` is shorthand for`--name`).
@@ -66,15 +68,15 @@
66
68
And then, to delete the environment use:
67
69
68
70
```bash
69
-
conda env remove -n bestpractices
71
+
conda remove -n bestpractices --all
70
72
```
71
73
72
74
Try running `conda env list` and you will see you have no environments other than `base`.
73
75
74
76
6. Now let's try to create an environment *with* Python. Type:
75
77
76
78
```bash
77
-
conda env create -n bestpractices python=3.13
79
+
conda create -n bestpractices python=3.13
78
80
```
79
81
(or pick a version of your choice). Activate your new environment as before and try:
80
82
@@ -123,7 +125,7 @@
123
125
conda env create -f environment.yml
124
126
```
125
127
This will create a new environment named `bestpractices_final` with
126
-
all the packages specified in the *environment.yml* file.
128
+
all the packages specified in the *environment.yml* file (`-f` is shorthand for `--file`).
127
129
Activating the new environment as before, using `conda activate bestpractices_final` (why is this the name?) and try running `python --version`. Try running `conda list` to see all the installed
128
130
packages. Everything listed in the `environment.yml` should be there, along with all
129
131
dependencies.
@@ -134,7 +136,7 @@
134
136
```
135
137
This will install all packages listed in a `requirements.txt` file from PyPI.
136
138
137
-
6. A final tip: append `--dry-run` to your `conda` commands to see what they will do without actually making any changes.
139
+
6. A final tip: append `--dry-run` to your `conda` commands to see what they will do without actually making any changes and refer to the [`conda` commands cheatsheet](https://docs.conda.io/projects/conda/en/latest/user-guide/cheatsheet.html#cheatsheet) if you're unsure about how to accomplish something.
138
140
139
141
## Some advice on projects and dependencies
140
142
@@ -145,4 +147,4 @@ Beyond using virtual environments, here are some best practices when it comes to
145
147
- For *portability* and ability to incorporate your code into other projects, avoid pinning versions strictly: pin to the minimum version required for the functionality you need.
146
148
- In addition to your environment file, for maximal reproducibility, consider generating **a lock file**, which specifies the *exact versions of all packages and their dependencies* in your environment. This can be done with `conda` using [conda-lock](https://github.com/conda/conda-lock) or with `pip` using [pip-tools](https://github.com/jazzband/pip-tools/). (Additionally, both `uv` and `pixi` automatically generate lock files.)
147
149
- If you will be sharing your code or expect others to run it, consider making a Python package. Check out the [pyOpenSci Python Package Guide](https://www.pyopensci.org/python-package-guide/index.html) for more details on how to do that!
0 commit comments