|
| 1 | +# Conda environment |
| 2 | + |
| 3 | +[this page is adapted from <https://aaltoscicomp.github.io/python-for-scicomp/installation/>] |
| 4 | + |
| 5 | +You only need this if you wish to go through examples and exercises during the |
| 6 | +second workshop week on your own computer. |
| 7 | + |
| 8 | + |
| 9 | +## Choosing an installation method |
| 10 | + |
| 11 | +For this course we will install an **isolated environment** |
| 12 | +with following dependencies: |
| 13 | +:::::{tabs} |
| 14 | + ::::{tab} environment.yml |
| 15 | + :::{literalinclude} software/environment.yml |
| 16 | + :language: yaml |
| 17 | + ::: |
| 18 | + :::: |
| 19 | + |
| 20 | + ::::{tab} requirements.txt |
| 21 | + :::{literalinclude} software/requirements.txt |
| 22 | + ::: |
| 23 | + :::: |
| 24 | +::::: |
| 25 | + |
| 26 | +:::{admonition} If you have a tool/method that works for you, keep using it |
| 27 | +If you are used to installing Conda packages and know what to do with the |
| 28 | +above files, please follow your own preferred installation |
| 29 | +method. |
| 30 | + |
| 31 | +**If you are new to Conda or unsure** how to create isolated environments from |
| 32 | +files above, please follow the instructions below where we do this with the help |
| 33 | +of Miniforge. |
| 34 | + |
| 35 | +If you already use **Anaconda** to manage your software environments, please |
| 36 | +continue using it. In this case you can skip {ref}`miniforge` and go directly to |
| 37 | +{ref}`conda-environment`. |
| 38 | +::: |
| 39 | + |
| 40 | + |
| 41 | +:::{admonition} Why do we recommend Miniforge and how does it relate to Conda? |
| 42 | +:class: dropdown |
| 43 | + |
| 44 | +There are many choices and we try to suggest a good compromise |
| 45 | +There are very many ways to install packages with pros and cons and |
| 46 | +in addition there are several operating systems with their own quirks. This |
| 47 | +can be a huge challenge for beginners to navigate. It can also difficult for |
| 48 | +instructors to give recommendations for something which will work everywhere |
| 49 | +and which everybody will like. |
| 50 | + |
| 51 | +Below we will recommend **Miniforge** since it is free, open source, general, |
| 52 | +available on all operating systems, and provides a good basis for reproducible |
| 53 | +environments. However, it does not provide a graphical user interface during |
| 54 | +installation. |
| 55 | + |
| 56 | +But Miniforge is only one option. Unfortunately there are many options and a |
| 57 | +lot of jargon. Here is a crash course: |
| 58 | + |
| 59 | +- **Conda** is a package manager: it allows distributing and |
| 60 | + installing packages, and is designed for complex scientific |
| 61 | + code. |
| 62 | +- **Mamba** is a re-implementation of Conda to be much faster with |
| 63 | + resolving dependencies and installing things. |
| 64 | +- An **environment** is a self-contained collections of packages |
| 65 | + which can be installed separately from others. They are used so |
| 66 | + each project can install what it needs without affecting others. |
| 67 | +- **Anaconda** is a commercial distribution of Python+Conda+many |
| 68 | + packages that all work together. It used to be freely usable for |
| 69 | + research, but since ~2023-2024 it's more limited. Thus, we don't |
| 70 | + recommend it (even though it has a nice graphical user interface). |
| 71 | +- **conda-forge** is another channel of distributing packages that |
| 72 | + is maintained by the community, and thus can be used by anyone. |
| 73 | + (Anaconda's parent company also hosts conda-forge packages) |
| 74 | +- **Miniforge** is the installer recommended by the conda-forge community. It operates via the command line. |
| 75 | +- **Miniconda** is a distribution of conda pre-configured to use |
| 76 | + the Anaconda channels. |
| 77 | +::: |
| 78 | + |
| 79 | + |
| 80 | +(miniforge)= |
| 81 | + |
| 82 | +## Installing Miniforge |
| 83 | + |
| 84 | +Download the latest release from the [Miniforge download |
| 85 | +overview](https://conda-forge.org/download/). This installs the base, and from |
| 86 | +here other packages can be installed. |
| 87 | + |
| 88 | +Unsure what to download and what to do with it? |
| 89 | +::::{tabs} |
| 90 | + :::{group-tab} Windows |
| 91 | + You want to download and run `Miniforge3-Windows-x86_64.exe`. |
| 92 | + |
| 93 | + When viewing the "Advanced installation options" step of the installer, |
| 94 | + leave the "Create shortcuts (supported packages only)." option **checked**, |
| 95 | + otherwise it will be difficult to launch the Miniforge prompt later. |
| 96 | + ::: |
| 97 | + |
| 98 | + :::{group-tab} MacOS |
| 99 | + You probably want to download the `Miniforge3-MacOSX-arm64.sh` file (unless |
| 100 | + you don't have an Arm processor) and then run it in the terminal with: |
| 101 | + ```console |
| 102 | + $ bash Miniforge3-MacOSX-arm64.sh |
| 103 | + ``` |
| 104 | + ::: |
| 105 | + |
| 106 | + :::{group-tab} Linux |
| 107 | + You probably want to download the `Miniforge3-Linux-x86_64.sh` file (unless |
| 108 | + you don't have an x86_64 processor) and then run it in the terminal with: |
| 109 | + ```console |
| 110 | + $ bash Miniforge3-Linux-x86_64.sh |
| 111 | + ``` |
| 112 | + ::: |
| 113 | +:::: |
| 114 | + |
| 115 | + |
| 116 | +(conda-environment)= |
| 117 | + |
| 118 | +## Installing the software environment |
| 119 | + |
| 120 | +First we will start a command line environment in a way that activates |
| 121 | +conda/mamba. Then we will install the software environment from [this |
| 122 | +environment.yml |
| 123 | +file](https://raw.githubusercontent.com/coderefinery/software/main/environment.yml) |
| 124 | +(this is the same file as on top of this page). |
| 125 | + |
| 126 | +An **environment** is a self-contained set of extra libraries - different |
| 127 | +projects can use different environments to not interfere with each other. This |
| 128 | +environment will have all of the software needed for this particular course. |
| 129 | + |
| 130 | +We will call the environment `coderefinery`. |
| 131 | + |
| 132 | +::::{tabs} |
| 133 | + :::{group-tab} Windows |
| 134 | + Use the "Miniforge Prompt" to start Miniforge. This |
| 135 | + will set up everything so that ``conda`` and ``mamba`` are |
| 136 | + available. |
| 137 | + Then type |
| 138 | + (without the `$`): |
| 139 | + ```console |
| 140 | + $ curl "https://raw.githubusercontent.com/coderefinery/software/main/environment.yml" -o environment.yml |
| 141 | + $ mamba env create -n coderefinery -f environment.yml |
| 142 | + ``` |
| 143 | + ::: |
| 144 | + |
| 145 | + :::{group-tab} Linux / MacOS |
| 146 | + Each time you start a new command line terminal, |
| 147 | + you can activate Miniforge by running |
| 148 | + (without the `$`): |
| 149 | + ```console |
| 150 | + $ source ~/miniforge3/bin/activate |
| 151 | + ``` |
| 152 | + |
| 153 | + This is needed so that |
| 154 | + Miniforge is usable wherever you need, but doesn't affect any |
| 155 | + other software on your computer (this is not needed if you |
| 156 | + choose "Do you wish to update your shell profile to |
| 157 | + automatically initialize conda?", but then it will always be |
| 158 | + active). |
| 159 | + |
| 160 | + In the second step, we will install the software environment by first copying the definition file: |
| 161 | + ```console |
| 162 | + $ curl "https://raw.githubusercontent.com/coderefinery/software/main/environment.yml" -o environment.yml |
| 163 | + $ mamba env create -n coderefinery -f environment.yml |
| 164 | + ``` |
| 165 | + ::: |
| 166 | +:::: |
| 167 | + |
| 168 | + |
| 169 | +(activating-environment)= |
| 170 | + |
| 171 | +## Activating the software environment |
| 172 | + |
| 173 | +::::{tabs} |
| 174 | + :::{group-tab} Windows |
| 175 | + Start the Miniforge Prompt. Then type |
| 176 | + (without the `$`): |
| 177 | + ```console |
| 178 | + $ conda activate coderefinery |
| 179 | + $ jupyter-lab |
| 180 | + ``` |
| 181 | + ::: |
| 182 | + |
| 183 | + :::{group-tab} Linux / MacOS |
| 184 | + Start the terminal and in the terminal, type |
| 185 | + (without the `$`): |
| 186 | + ```console |
| 187 | + $ source ~/miniforge3/bin/activate |
| 188 | + $ conda activate coderefinery |
| 189 | + $ jupyter-lab |
| 190 | + ``` |
| 191 | + ::: |
| 192 | +:::: |
| 193 | + |
| 194 | + |
| 195 | +## How to verify the environment |
| 196 | + |
| 197 | +Make sure you are in the Miniforge prompt (Windows) or in a terminal (Linux/MacOS). |
| 198 | + |
| 199 | +The following command should return a version number and not an error message: |
| 200 | +```console |
| 201 | +$ conda --version |
| 202 | +``` |
| 203 | + |
| 204 | +Is the coderefinery environment installed? |
| 205 | +```console |
| 206 | +$ conda env list |
| 207 | +``` |
| 208 | + |
| 209 | +Make sure it's activated ({ref}`activating-environment`). |
| 210 | +Once activated, try the following commands. |
| 211 | + |
| 212 | +You should see versions printed and not see errors (exact version numbers are not too important): |
| 213 | +```console |
| 214 | +$ jupyter-lab --version |
| 215 | + |
| 216 | +4.1.2 |
| 217 | + |
| 218 | +``` |
| 219 | +```console |
| 220 | +$ pytest --version |
| 221 | + |
| 222 | +8.0.2 |
| 223 | +``` |
| 224 | + |
| 225 | +```console |
| 226 | +$ sphinx-build --version |
| 227 | + |
| 228 | +sphinx-build 7.2.6 |
| 229 | +``` |
| 230 | + |
| 231 | +```console |
| 232 | +$ snakemake --version |
| 233 | + |
| 234 | +8.5.3 |
| 235 | +``` |
| 236 | + |
| 237 | + |
| 238 | +## Removing the software environment |
| 239 | + |
| 240 | +::::{tabs} |
| 241 | + :::{group-tab} Windows |
| 242 | + In the Miniforge Prompt, type |
| 243 | + (without the `$`): |
| 244 | + ```console |
| 245 | + $ conda env list |
| 246 | + $ conda env remove --name coderefinery |
| 247 | + $ conda env list |
| 248 | + ``` |
| 249 | + ::: |
| 250 | + |
| 251 | + :::{group-tab} Linux / MacOS |
| 252 | + In the terminal, type |
| 253 | + (without the `$`): |
| 254 | + ```console |
| 255 | + $ source ~/miniforge3/bin/activate |
| 256 | + $ conda env list |
| 257 | + $ conda env remove --name coderefinery |
| 258 | + $ conda env list |
| 259 | + ``` |
| 260 | + ::: |
| 261 | +:::: |
0 commit comments