To create a personal python virtual environment in the /userapp/virtualenv/project_name folder. Any user in your project can use this virtual environment.
srun -A {slurm_account_name} --time=00:10:00 --pty bash. Replace {slurm_account_name} with your SLURM account name.So to create a virtual environment
[username@arclogin01 ~]$ cd ~
[username@arclogin01 ~]$ module load python
[username@arclogin01 ~]$ mkdir -p /userapp/virtualenv/project_name/venv
[username@arclogin01 ~]$ python3 -m venv /userapp/virtualenv/project_name/venv
To use the virtual environment, you first must activate it. This is done by source {foldername}/bin/activate
For our use case of ~/venv,
[username@arclogin01 ~]$ source /userapp/virtualenv/project_name/venv/bin/activate
Once activate, you will see the following on the command line.
(venv) [username@arclogin01 ~]$
The (venv) tells you that your virtual environment is activated.
Ensure that your virtual environment is running the latest version of pip.
(venv) [username@arclogin01 ~]$ pip install --upgrade pip
To install packages to your virtual environment, use pip as after the virtual environment is activated.
(venv) [username@arclogin01 ~]$ pip install numpy
When submitting a job using sbatch and before running your python script in your job submission file, be sure to activate your virtual environment in the script directly after loading the module. Otherwise, your packages will not be available.
...
source /userapp/virtualenv/project_name/venv/bin/activate
...