...
Virtual environments are a convenient way for you to have complete control over potentially many versions of Python. The LMS provides the conda utility to allow you to create and manage virtual Python environments. This page describes the basics of using conda, as well as some LMS-specific configuration that you are likely to find useful. The full documentation of conda, can be found in the conda online documentation.
Initial Setup
By default, conda will create environments and install packages into subdirectories of your HOME directory, which will end up containing a vast number of files. To avoid hitting quota limits, you can tell conda to store files in your scratch shared storage space instead, which is much larger. To do this, you need to work through these steps.
Info |
---|
Contact your department for access to some shared storage space, this will probably be under |
1.Create directories in your scratch shared storage space to contain your Python environments and packages. This can be achieved by running the following commands in a shell (N.B double check this is the correct path to where you wish to store your packages)
Code Block |
---|
cd ~ mkdir -p /scratchshared/storage/biology/USERNAME/python_environments/envs mkdir -p /scratchshared/storage/biology/USERNAME/python_environments/pkgs |
2. Create a configuration file for conda in your HOME directory called ".condarc" and add the following to tell conda to use the directories you created in step 1. Ensure you replace "USERNAME" in the directory with your IT services username.
Code Block |
---|
envs_dirs: - /scratchshared/storage/biology/USERNAME/python_environments/envs pkgs_dirs: - /shared/storage/scratchbiology/USERNAME/python_environments/pkgs |
...
Code Block |
---|
module load lang/Miniconda3 |
Creating an environment
The most reliable way to create an environment using conda is by using an environment file. This is a .yaml file that describes the Python environment you would like to create. This method allows you to recreate the same environment in multiple places, and easily pass on the specification for a Python environment to other users. A simple example of an environment file is given below.
...
To create a python environment, you will need to create a yaml file, in either your scratch shared storage or HOME directory.
Now you have an environment file, you can create that environment using conda. Using my_first_environment.yaml as an example:
...
This will list all of the environments installed with conda, and in this example we can see that my_first_environment has been successfully created. Note the asterisk highlights the active environment, which is currently the base environment (over which you have no control).
Using an environment
Once an environment has been created, you can activate it with the following command:
...