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)
- Log into the Linux compute servers and open a terminal window.
- Load the Anaconda module
- module load anaconda3
- Initialize anaconda.
- conda init tcsh
- Log off the server and reconnect to the compute server.
Create your first environment
- Use conda to create a named virtual environment using your preferred version of Python.
-
conda create --name environment_name python=python_version
- e.g. conda create --name test_environment python=3.8
-
conda create --name environment_name python=python_version
Using your virtual environments.
- Activate your preferred environment
-
conda activate environment_name
- e.g. conda activate test_environment
-
conda activate environment_name
- Install Python packages, run a python program, or start the interpreter
- Install packages
-
conda install package_name
or - pip install package_name
-
conda install package_name
- Run a Python program.
- python my_program.py
- Start the intrepreter.
- python
- Install packages
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
-
python3 -m virtualenv environment_name
-
e.g. python3 -m virtualenv test_environment
- This creates a folder in your current working directory that contains the environment.
-
e.g. python3 -m virtualenv test_environment
Using your virtual environments
- Activate your environment
-
source path_to_environment_folder/environment_name/activate.csh
- e.g. source ~/test_environment/activate.csh
-
source path_to_environment_folder/environment_name/activate.csh
- Install Python Packages, run a python program, or start the interpreter
- Install packages.
- pip install package_name
- Run a Python program.
- python my_program.py
- Start the intrepreter.
- python
- Install packages.
When done using the environment, log out or deactivate with the command "deactivate"