---
# System prepended metadata

title: Conda environments in VSCode

---

# Conda environments in VSCode

## Activating your base environment in VSCode

We first want to set up VSCode to automatically activate your base python environment. The point of the base environment is that if you’re downloading python packages, it will save them to your base by default. So between environments that you have activated, if you already have a package available in your base package directory, it will automatically use that. 

1. Activate base conda environment (may need to execute `module load conda` first)
`conda init`
2. Start a fresh terminal to source the base environment
3. This command adds the line below to your`.bashrc` that automatically initializes your base environment in vscode, so when you type `which python`, it should match the folder path below (eg `/panfs/roc/msisoft/anaconda/python3-2020.07-mamba/bin` in this example):

```
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/panfs/roc/msisoft/anaconda/python3-2020.07-mamba/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/panfs/roc/msisoft/anaconda/python3-2020.07-mamba/etc/profile.d/conda.sh" ]; then
        . "/panfs/roc/msisoft/anaconda/python3-2020.07-mamba/etc/profile.d/conda.sh"
    else
        export PATH="/panfs/roc/msisoft/anaconda/python3-2020.07-mamba/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<
```

Note that your base environment is automatically located in your home directory, but you can store your packages in an external file path to prevent your home directory from getting filled up by adding an external path to your `~/.condarc`. For example you can add the following lines to thee top of this file, where `SHARE` is replaced by whichever MSI share you would like `MSI_USERNAME` is replaced with your own username:


```
pkgs_dirs:
  - /home/<SHARE>/shared/code/external/envs/<MSI_USERNAME>/conda/pkgs
```

If your `.condarc` file does not yet exist, you can generate it with the following steps:


## Creating a new conda environment

Each repository should include its own conda environment so that different users are sourcing consistent package versions. Some packages can also be a little tricky to set up, so this removes the initial work for people setting up to use a repository.

Use `conda create` to create a new conda environment. The example below sets up an environment for a repository named "testrepo":
`conda create —prefix /home/faird/shared/code/external/envs/testrepo-env python=3.9`


## Activating an existing environment in VSCode