optimal Conda environment setup

From Conda 4.4 onward, it’s recommended to NOT simply add the Anaconda bin directory to your PATH, as this can cause library version conflicts. It’s much more appropriate, speedy and effective to follow this setup (for Linux and MacOS). Again, in ~/.bashrc, do NOT “export PATH” with anaconda/bin anymore.

  1. in ~/.bashrc, add a line like:
    . $HOME/miniconda3/etc/profile.d/conda.sh

    After that, new terminal sessions will not have Anaconda/Conda etc. on the PATH. Be sure the old PATH for anaconda/bin or miniconda/bin isn’t there anymore–but leave other “export PATH” statements alone.

  2. To add the Python / Conda executable path, type:
    conda activate

Keyboard shortcut

To avoid doing the second step constantly, setup a custom keyboard shortcut pointing to a executable script ~/pyterm.sh that contains something like (as appropriate for your system):


source $HOME/miniconda3/etc/profile.d/conda.sh

conda activate base


the keyboard shortcut on Linux should call

x-terminal-emulator -e $HOME/pyterm.sh

and then you can typically use the new keyboard shortcut when you want to use Python, and your old keyboard shortcut when you don’t want Anaconda interfering with your system environment.



Written by Michael Hirsch, Ph.D. //