Created
September 5, 2024 04:50
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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