Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have tmux windows inherit `activate`d anaconda environment

Tags:

For convenience and given that activate-ing an environment is crazy slow, I want to activate an environment and then start a tmux session.

I want all new tmux windows to also have the environment activated.

I want different tmux sessions to be able to support different anaconda environments.

How do I go about this?

Are there any gotchas such that this isn't supported by anaconda / miniconda?

like image 840
Tom Hale Avatar asked Apr 30 '19 04:04

Tom Hale


People also ask

How do you activate an Anaconda environment window?

If you receive this warning, you need to activate your environment. To do so on Windows, run: c:\Anaconda3\Scripts\activate base in Anaconda Prompt. Windows is extremely sensitive to proper activation.

How can I activate conda environment automatically?

Reload Window from Command Palette, select base:conda as python interpreter then press Ctrl+Shift+` to open a new integrated Terminal, conda environment should be activated automatically in it.

How do you activate and deactivate Anaconda environment?

To activate your Conda environment, type source activate <yourenvironmentname> . Note that conda activate will not work on Discovery with this version. To install a specific package, type conda install -n <yourenvironmentname> [package] . To deactivate the current, active Conda environment, type conda deactivate .


1 Answers

What I've done to address this problem is:

  • In .tmux.conf, copy CONDA_DEFAULT_ENV environment variable to session environment
    set-option -ga update-environment 'CONDA_DEFAULT_ENV'
    
  • In .bashrc, reactivate the conda environment if one was activated:
    if [ -n "$CONDA_DEFAULT_ENV" ]; then                                                                                                                                         
        __conda_reactivate                                                                                                                                                       
    fi
    
    Note 1: this assumes that __conda_reactivate is available because of conda init or similar. Note 2: in older versions of conda, it's _conda_reactivate (just one leading underscore).

This is faster than conda activate <env> and also different environments can be used before creating different tmux sessions.

like image 158
jcollado Avatar answered Sep 18 '22 09:09

jcollado