There is a fully automated way to do it so you don't have to manually deactivate and activate the environment each time. It's a combination of some of the other answers here. The first step is to open your .tmux.conf
file and find the line set -g default-command
and add to it so that it says set -g default-command "${SHELL}"
(Note: It might also say set-option -g default-command
; set
is an alias of set-option
, so either is fine).
Then, in your initialization scripts, after the conda initialize section that conda automatically adds, you'll need to deactivate and then re-activate your conda. Here's one way to do that:
I recommend people use a .profile
file to customize their environment. To do that, you can source .profile
from your .bashrc
/.zshrc
file (depending on which shell you use). Then, take the conda initialization script that conda added and put it in .profile
. Then, after this, add conda deactivate
and conda activate my_conda_env
. Following the conda initialization, it should look like:
# <<< conda initialize <<<
conda deactivate
conda activate my_conda_env
It doesn't work without the conda deactivate
step, so be sure to include that.
You can test that this is working by entering which python
after you enter tmux and ensuring that it points to the correct python in your conda environment.