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
With this tool you can download and install with ``pip`` from the [PyPI repository](https://pypi.org/)
@@ -193,12 +192,9 @@ With this tool you can download and install with ``pip`` from the [PyPI reposito
193
192
194
193
- You can use "pip list" on the command line (after loading the python module) to see which packages are available and which versions.
195
194
- Some packages may be inherited from the modules you have loaded
196
-
- You can do ``pip list --local`` to see what is installed by you in the environment.
197
-
- Some IDE:s like Spyder may only find those "local" packages
198
195
- To save space, you should load any other Python modules you will need that are system installed before installing your own packages! Remember to choose ones that are compatible with the Python version you picked!
199
196
-``--system-site-packages`` includes the packages already installed in the loaded python module.
200
197
- The ``--no-cache-dir"`` option is required to **avoid it from reusing earlier installations from the same user in a different environment**.
201
-
- The ``--no-build-isolation`` is to make sure that it uses the loaded modules from the module system when **building any Cython libraries**.
202
198
:::
203
199
204
200
### Conda
@@ -225,81 +221,62 @@ With this tool you can download and install with ``pip`` from the [PyPI reposito
225
221
- scilifelab-lts
226
222
227
223
You reach them all by loading the conda module. You don't have to state the specific channel when using UPPMAX. Otherwise you do with ``conda -c <channel> ...``
228
-
224
+
:::
229
225
230
226
:::{warning}
231
227
232
-
Drawbacks
228
+
Drawbacks
233
229
234
-
- Conda cannot use already install packages from the Python modules and libraries already installed, and hence installs them anyway
235
-
- Conda is therefore known for creating **many***small* files. Your disk space is not only limited in GB, but also in number of files (typically ``300000`` in $HOME).
236
-
- Check your disk usage and quota limit
237
-
- Do a ``conda clean -a`` once in a while to remove unused and unnecessary files
230
+
- Conda cannot use already install packages from the Python modules and libraries already installed, and hence installs them anyway
231
+
- Conda is therefore known for creating **many***small* files. Your disk space is not only limited in GB, but also in number of files (typically ``300000`` in $HOME).
232
+
- Check your disk usage and quota limit
233
+
- Do a ``conda clean -a`` once in a while to remove unused and unnecessary files
238
234
:::
239
235
240
236
:::{tip}
241
237
242
238
- The conda environments including many small files are by default stored in ``~/.conda`` folder that is in your $HOME directory with limited storage.
243
-
- Move your ``.conda`` directory to your project folder and make a soft link to it from ``$HOME``
244
-
- Do the following (``mkdir -p`` ignores error output and will not recreate another folder if it already exists):
245
-
- (replace what is inside ``<>`` with relevant path)
246
-
247
-
- Solution 1
248
-
249
-
This works nicely if you have several projects. Then you can change these variables according to what you are currently working with.
# A prompt "(/path-to/nsc-example/)" should show up
259
+
# double-check we are using python from the Conda environment!
260
+
which python # should point to the conda environment!
261
+
python -V # should give python version 3.9.5
262
+
conda install numpy
263
+
```
285
264
286
-
```python
265
+
```python
287
266
288
-
>>> import numpy
289
-
```
267
+
>>>import numpy
268
+
```
290
269
:::
291
270
292
-
:::{admonition} Comments
293
-
:class: dropdown
294
-
295
-
- When pinning with Conda, use single ``=`` instead of double (as used by pip)
271
+
- Note, hen pinning with Conda, use single ``=`` instead of double (as used by pip)
296
272
:::
297
273
298
274
:::{admonition} Conda base env
299
275
:class: dropdown
300
276
301
-
- When conda is loaded you will by default be in the base environment, which works in the same way as other conda environments.
302
-
- It includes a Python installation and some core system libraries and dependencies of Conda. It is a “best practice” to avoid installing additional packages into your base software environment.
277
+
- When conda is loaded you will by default be in the *base environment*, which works in the same way as other conda environments.
278
+
- It includes a Python installation and some core system libraries and dependencies of Conda.
279
+
- It is a “best practice” to avoid installing additional packages into your base software environment.
303
280
304
281
:::{admonition} Conda cheat sheet
305
282
@@ -321,29 +298,28 @@ With this tool you can download and install with ``pip`` from the [PyPI reposito
- If you experience unexpected problems with the conda provided by the module system on Rackham or anaconda3 on Dardel, you can easily install your own and maintain it yourself.
328
-
- Read more at [Pavlin Mitev's page about conda on Rackham/Dardel](https://hackmd.io/@pmitev/conda_on_Rackham) and change paths to relevant one for your system.
329
-
- Or [Conda - "best practices" - UPPMAX](https://hackmd.io/@pmitev/module_conda_Rackham)
330
-
:::
331
-
332
301
## Install from file
333
302
334
-
- All centers has had different approaches in what is included in the module system and not.
335
-
- Therefore the solution to complete the necessary packages needed for the course lessons, different approaches has to be made.
336
-
- This is left as exercise for you, see Exercise 4 and 5.
303
+
-This is handy when you want to move your Python environment somewhere else.
304
+
-Also, when giving your code to someone else (in research group or to a community).
305
+
-Good for reproducibility
337
306
338
-
### venv
307
+
:::{admonition} Principle for both ``venv`` & ``conda``
308
+
1. Activate the environment and make sure it works
309
+
2. Save a environment file
310
+
3. Distribute the file
311
+
4. Receiver installs the environment from the file
312
+
:::
339
313
314
+
### venv
340
315
341
316
Make a requirements file:
342
317
343
318
```console
344
319
345
-
pip freeze --local > requirements.txt
320
+
pip freeze --local > requirements.txt
346
321
```
322
+
347
323
:::{admonition} How does it look like?
348
324
:class: dropdown
349
325
@@ -360,6 +336,7 @@ Make a requirements file:
360
336
python-dateutil==2.9.0.post0
361
337
six==1.17.0
362
338
```
339
+
:::
363
340
364
341
Install packages from a file
365
342
@@ -440,6 +417,10 @@ Create an environment from a file. Do this on another computer or rename.
440
417
441
418
## Exercises
442
419
420
+
- All centers has had different approaches in what is included in the module system and not.
421
+
- Therefore the solution to complete the necessary packages needed for the course lessons, different approaches has to be made.
422
+
- This is left as exercise for you, see Exercise 4 and 5.
423
+
443
424
:::{challenge} Exercise 0: Make a decision between ``venv`` or ``conda``.
444
425
445
426
- We recommend `conda` for LUNARC.
@@ -1028,9 +1009,7 @@ Breakout room according to grouping
1. Start from a Python version you would like to use (load the module):
1084
-
- This step are different at different clusters since the naming is different
1085
-
1086
-
2. Load the Python module you will be using, as well as any site-installed package modules (requires the ``--system-site-packages`` option later)
1087
-
- ``module load <python module>``
1088
-
1089
-
The next points will be the same for all clusters
1090
-
1091
-
3. Create the isolated environment with something like ``python -m venv <name-of-environment>``
1092
-
- use the ``--system-site-packages`` to include all "non-base" packages
1093
-
- include the full path in the name if you want the environment to be stored other than in the "present working directory".
1094
-
1095
-
4. Activate the environment with ``source <path to virtual environment>/bin activate``
1096
-
1097
-
:::{note}
1098
-
1099
-
- ``source`` can most often be replaced by ``.``, like in``. Example/bin/activate``. Note the important <space> after ``.``
1100
-
- For clarity we use the ``source`` style here.
1101
-
:::
1102
-
1103
-
5. Install (or update) the environment with the packages you need with the ``pip install``command
1104
-
1105
-
- Note that ``--user`` must be omitted: else the package will be installed in the global user folder.
1106
-
- The ``--no-cache-dir"`` option is required to avoid it from reusing earlier installations from the same user in a different environment. The ``--no-build-isolation`` is to make sure that it uses the loaded modules from the module system when building any Cython libraries.
1107
1063
1108
-
6. Work in the isolated environment
1109
-
- When activated you can always continue to add packages!
1110
-
7. Deactivate the environment after use with ``deactivate``
1111
-
1112
-
:::{note}
1113
-
1114
-
To save space, you should load any other Python modules you will need that are system installed before installing your own packages! Remember to choose ones that are compatible with the Python version you picked!
1115
-
``--system-site-packages`` includes the packages already installed in the loaded python module.
1116
-
1117
-
At HPC2N, NSC and LUNARC, you often have to load SciPy-bundle. This is how you on Tetralith (NSC) could create a venv (Example) with a SciPy-bundle included which is compatible with Python/3.11.5:
1118
-
1119
-
```console
1120
-
1121
-
$ module load buildtool-easybuild/4.8.0-hpce082752a2 GCC/13.2.0 Python/3.11.5 SciPy-bundle/2023.11 # for NSC
1122
-
$ python -m venv --system-site-packages Example
1123
-
```
1124
-
:::
1125
-
1126
-
:::{warning}
1127
-
1128
-
Draw-backs
1129
-
1130
-
- Only works for Python environments
1131
-
- Only works with Python versions already installed
1132
-
:::
1133
-
1134
-
Typical workflow Conda
1135
-
......................
1136
-
1137
-
The first 2 steps are cluster dependent and will therefore be slightly different.
1138
-
1139
-
1. Make conda available from a software module, like ``ml load conda`` or similar, or use own installation of miniconda or miniforge.
1140
-
2. First time
1141
-
1142
-
:::{admonition} First time
1143
-
:class: dropdown
1144
-
1145
-
- The variables CONDA_ENVS_PATH and CONDA_PKG_DIRS contains the location of your environments. Set it to your project's environments folder, if you have one, instead of the $HOME folder.
0 commit comments