Skip to content

Instantly share code, notes, and snippets.

@achadha235
Created September 5, 2024 04:50
Show Gist options
  • Select an option

  • Save achadha235/485a1833d79c09d13dcbf896a1b25171 to your computer and use it in GitHub Desktop.

Select an option

Save achadha235/485a1833d79c09d13dcbf896a1b25171 to your computer and use it in GitHub Desktop.
A convenience script to activate a conda environment in a given directory and make sure the correct binary is discoverable
activate_pyenv() {
if [[ -f ./.conda-env ]]; then
env_name=$(cat ./.conda-env)
conda activate "$env_name"
## This is to ensure that the python executable for conda is in the PATH and overrides any executables in
python_executable_path=$(dirname $(which python))
## add this to the front of the PATH
export PATH="$python_executable_path:$PATH"
fi
## TODO: probably add something to track what environment is active and deactivate automatically as well
}
# Optionally call the function to activate environment on shell startup or when changing directories
activate_pyenv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment