I want to run a script on cluster (SBATCH file). How can active my virtual environment (path/to/env_name/bin/activate). Does i need only to add:
module load python/2.7.14
source "/pathto/Python_directory/ENV2.7_new/bin/activate"
in my_script.sh file?
You mean to activate a specific Python environment as part of your submission to Slurm? This is what I add to my job script and it works well. Note that I use Anaconda, which by default adds the required paths to my .bashrc script after installation. Hope this helps.
....
# define and create a unique scratch directory
SCRATCH_DIRECTORY=/global/work/${USER}/kelp/${SLURM_JOBID}
mkdir -p ${SCRATCH_DIRECTORY}
cd ${SCRATCH_DIRECTORY}
# Activate Anaconda work environment for OpenDrift
source /home/${USER}/.bashrc
source activate MyEnvironment
# we execute the job and time it
time mpirun python slurmscript.py