When using Python on the Linux compute servers, we recommend using Python Virtual Environments. This allows you to install your own packages and reduces library conflicts. 


There are two ways to start using virtual environments on the Linux compute servers.


Using Anaconda to create virtual environments.


Set up Anaconda (Only need to do this once)

  1. Log into the Linux compute servers and open a terminal window.
  2. Load the Anaconda module
    1. module load anaconda3
  3. Initialize anaconda.
    1. conda init tcsh
  4. Log off the server and reconnect to the compute server.


Create your first environment

  1. Use conda to create a named virtual environment using your preferred version of Python.
    1. conda create --name environment_name python=python_version
      • e.gconda create --name test_environment python=3.8 


Using your virtual environments.

  1. Activate your preferred environment
    1. conda activate environment_name
      • e.g. conda activate test_environment
  2. Install Python packages, run a python program, or start the interpreter
    1. Install packages
      1. conda install package_name
        or
      2. pip install package_name
    2. Run a Python program.
      1. python my_program.py
    3. Start the intrepreter.
      1. python


When done using the environment, log out or deactivate the environment with the command "conda deactivate"


Using the Virtualenv Python module.


Create your first environment

  1. python3 -m virtualenv environment_name
    1. e.g. python3 -m virtualenv test_environment
      1. This creates a folder in your current working directory that contains the environment.


Using your virtual environments

  1. Activate your environment
    1. source path_to_environment_folder/environment_name/activate.csh
      • e.g. source ~/test_environment/activate.csh
  2. Install Python Packages, run a python program, or start the interpreter
    1. Install packages.
      1. pip install package_name
    2. Run a Python program.
      1. python my_program.py
    3. Start the intrepreter.
      1. python


When done using the environment, log out or deactivate with the command "deactivate"