Basic Setup
We will briefly describe how to setup a virtual environment manually. There are several programs which will manage virtual environments for you, like pipenv or conda, but they may not be flexible enough, depending on your use case. We also strongly advise to create your virtual environments on the scratch partion of the host your are using. If you need to install many packages, the virutal environment will be very big and you may run out of disk space in your home directory.
Firstly, create a folder for your project like
[ga45can@cip2ryzen3] ~ $ mkdir -p /scratch/ga45can/My_Awesome_Python_Project
Secondly, create a hidden folder inside your project folder for the virutal environment. This step is not necessary, but it helps to keep your project folder clean. The folder can have an arbitrary name.
[ga45can@cip2ryzen3] /scratch/ga45can/My_Awesome_Python_Project $ mkdir .venv
Now we can create the virutal environment
[ga45can@cip2ryzen3] /scratch/ga45can/My_Awesome_Python_Project $ virtualenv .venv/
created virtual environment CPython3.8.10.final.0-64 in 360ms
creator CPython3Posix(dest=/scratch/ga45can/My_Awesome_Python_Project/.venv, clear=False, global=False)
seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, pkg_resources=latest, via=copy, app_data_dir=/home/stud/ga45can/.local/share/virtualenv/seed-app-data/v1.0.1.debian.1)
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
and enter it with
[ga45can@cip2ryzen3] /scratch/ga45can/My_Awesome_Python_Project $ source .venv/bin/activate
(.venv) [ga45can@cip2ryzen3] /scratch/ga45can/My_Awesome_Python_Project $
The change of the command prompt indicates we successfully entered the environment. Now we can install all the packages we desire, like
(.venv) [ga45can@cip2ryzen3] /scratch/ga45can/My_Awesome_Python_Project $ pip install tensorflow
Collecting tensorflow
....
Workaround for large packages
In case you do not have much space left in your home directory and you need to install large packages like PyTorch (~800MB), the install might fail because pip is caching the downloading package before the install in $HOME/.cache. To get around this problem you could symlink your local cache directory to some directory you create on the scratch parition or we tell pip not to cache the downloaded downloading package in you home directory. To achieve that we need to overwrite the environment variable TEMPDIR temporarily for the install like
(.venv) [ga45can@cip2ryzen2] /scratch/ga45can/My_Awesome_Python_Project $ TMPDIR=/scratch pip install torch