Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
doku:python [2023/04/17 08:14] – [Optional: execute conda hooks on login] katrindoku:python [2023/06/19 08:33] katrin
Line 1: Line 1:
-====== Python ======+====== Python in VSC ====== 
 + 
 +===== (Conda) Quickstart ===== 
 + 
 +To install a new environment start with creating an environment yaml file and store it in a safe location (ideally in your source code repository). This step is optional but we really recommend it so you and everyone in your team is able to produce the same python environment. 
 +<code> 
 +name: my-env 
 +dependencies: 
 +  - python=3.10 
 +  - tensorflow-gpu=2.6.0 
 +</code> 
 + 
 +<code> 
 +# load the miniconda package 
 +$ module load miniconda3 
 + 
 +# executes bash hooks for the tool to function 
 +# and enters the "base" environment 
 +$ eval "$(conda shell.bash hook)" 
 + 
 +# create your environment via environment file 
 +(base) $ conda create -n my-env --file my_env.yaml 
 + 
 +# after creation you can activate the environment to run code in it 
 +(base) $ conda activate my-env 
 + 
 +# test python version to make sure we have the right one 
 +(my-env) $ python --version 
 +Python 3.10.11 
 +</code> 
 + 
 +You can now start developing and even just use the environment in a slurm script 
 + 
 +<code> 
 +#!/bin/bash 
 + 
 +#SBATCH --job-name=slurm_conda_example 
 +#SBATCH --time 00-00:05:00 
 +#SBATCH --ntasks=2 
 +#SBATCH --mem=2GB 
 + 
 +# modify SBATCH options according to needs 
 + 
 +# see "Setup Conda" above or consult "module avail miniconda3" to get the right package name 
 +module load MINICONDA3_PACKAGE_NAME 
 +eval "$(conda shell.bash hook)" 
 +conda activate myenv 
 + 
 +# print out some info of the python executable in use 
 +# this should point to the python version from "myenv" 
 +which python 
 +python --version 
 +</code> 
 + 
 +==== FAQ ==== 
 + 
 +**I see the error '''ModuleNotFoundError: No module named "conda"''' in my slurm job logfile. What is wrong>?** 
 + 
 +The default for sbatch is to use the current user environment and start the job in the context of this environment. Since conda is depending on environment variables being setup correctly you need to ake sure to start the job script from a clean environment. Alternatively you can also use sbatch with the '''--export=NONE''' argument. 
 + 
 +====== Deprecated Information (work in progress) ======
  
 ===== Python Installations ===== ===== Python Installations =====
Line 36: Line 96:
 ==== Setup Conda ==== ==== Setup Conda ====
  
-To load ''conda'' on our clusters search for the ''miniconda3'' package. At the time of writing the ''miniconda3'' package is available on both VSC-4 & VSC-5 and can be loaded via +To use the ''conda'' tool on our clusters search for the ''miniconda3'' package. At the time of writing the ''miniconda3'' package is available in all environments on both VSC-4 & VSC-5 and can be loaded with 
 <code bash> <code bash>
-# VSC-4 +module load miniconda3
-module load miniconda3/4.12.0-gcc-12.2.0-pad7sa7 +
- +
-# VSC-5 +
-module load miniconda3/4.12.0-gcc-11.2.0-ap65vga+
 </code> </code>
  
  • doku/python.txt
  • Last modified: 2024/03/19 14:24
  • by katrin