I recently started over with a fresh development environment and decided to try something new: I’m using Python 3 via miniconda. The first real hiccup I’ve run into is that conda’s environment activation/deactivation scheme only works in bash or zsh. I use fish. There is an open PR to get fish support for conda but in the meantime I hacked something together to help me out.
"Activating" a conda environment does a couple of things:
- Puts the environment’s "bin" directory at the front of the
PATH
environment variable.
- Sets a
CONDA_DEFAULT_ENV
environment variable that tells conda in which environment to do things when none is specified.
- Adds the environment name to the prompt ala virtualenv.
Deactivating the environment resets everything to its pre-activation state. The fish
functions I put together work like this:
~ > type python
python is /Users/---/miniconda3/bin/python
~ > condactivate env-name
(env-name) ~ > type python
python is /Users/---/miniconda3/envs/env-name/bin/python
(env-name) ~ > deactivate
~ > type python
python is /Users/---/miniconda3/bin/python
Here’s the text of the functions:
Or you can download it from https://gist.github.com/jiffyclub/9679788.
To use these, add them to the ~/.config/fish/
directory and source them from the end of the ~/.config/fish/config.fish
file:
source $HOME/.config/fish/conda.fish