Virtual environments allow us to create an isolated (or semi-isolated) python environment where we can install our own packages without requiring super-user privileges. This is useful in case you need a different version of a certain package or a package that isn’t installed, or if you want to be able to clean up quickly, or if you need a lot of disk space.
Note: the following commands should be run on the cluster. This can be done by preceding them with an srun command, by running in a batch with an sbatch command, or by starting a terminal session on a cluster node using the command srun --pty
, after which any command typed into the new terminal session will run on the cluster.
Creating a virtual environment should be done on a cluster node, using slurm. This section describes how to do this.
Once you have activated your virtual environment as described above, you can now install packages inside the virtualenv. UNDER CONSTRUCTION BOOKMARK LINK.
This is done with the pip command: pip install package-name
. To install a specific version of the package use: pip install package-name==version
To uninstall a package: pip uninstall package-name
Packages that come from a source with a setup.py can also be installed inside the virtualenv by typing: python setup.py install
When the installation of packages is finished you need to exit the virtualenv with this command: deactivate
To use the packages you installed in the virtual environment, you need to activate it as described above. UNDER CONSTRUCTION BOOKMARK LINK
After activating, any Python related commands will work from the virtualenv.
To get your script to use the Python interpreter from the virtualenv, put the following line at the beginning of your script: #!/usr/bin/env python
To verify that you are using the Python in the virtualenv with this command: which python
Its output should be: /sci/labs/<pi-user-name>/<your-user-name>/<venv-folder-name>/bin/python
When you finish working with the virtualenv deactivate it: deactivate
⚠️ Virtual Environments require use of the slurm workload manager ⚠️ HURCS reserves the right to kill processes running on the login node without further warning ⚠️